haolan Posted August 8, 2007 Share Posted August 8, 2007 Hi phpfreaks.. I am trying to create a function to remove one number from a textbox, just like a backspace button. I have made the following code: function backspace() { display = document.post_form.post_display.value; disp_length = display.length; newString = display.substring(0, disp_length - 1); document.post_form.post_display.value = newString.ToString(); } My form is named post_form and the textbox is named post_display. This code does not work.. What is wrong? Link to comment https://forums.phpfreaks.com/topic/63906-solved-backspace-aka-substring-function/ Share on other sites More sharing options...
emehrkay Posted August 8, 2007 Share Posted August 8, 2007 i always say it is easier/more accurate to reference an element by id document.getElementById('eleid').value = whatever; first alert newString and see if it is doing what you want. then use the reference by id technique Link to comment https://forums.phpfreaks.com/topic/63906-solved-backspace-aka-substring-function/#findComment-318679 Share on other sites More sharing options...
mainewoods Posted August 9, 2007 Share Posted August 9, 2007 change to 'minus 2' newString = display.substring(0, disp_length - 2); Link to comment https://forums.phpfreaks.com/topic/63906-solved-backspace-aka-substring-function/#findComment-319611 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.