sugarcube Posted May 12, 2010 Share Posted May 12, 2010 Hi guys, I'have a problem. I want to change a field with a button. my field: <input type=\"text\" name=\"invoerregel\"><br> my button: <input type=\"button\" name=\"1\" value=\"1\"> now is my question, how can ik change my button so, that every time I push the button it adds a 1 to the text field Link to comment https://forums.phpfreaks.com/topic/201483-ajax-and-php-change-text-field-with-a-button/ Share on other sites More sharing options...
Adam Posted May 12, 2010 Share Posted May 12, 2010 When you say 'adds a 1' do you mean increment the value by 1, or literally add a '1' onto the end of the string? Link to comment https://forums.phpfreaks.com/topic/201483-ajax-and-php-change-text-field-with-a-button/#findComment-1057104 Share on other sites More sharing options...
seventheyejosh Posted May 12, 2010 Share Posted May 12, 2010 // add one (string) <script type="text/javascript"> function addOne(){ document.getElementById('myText').innerHTML+='1'; }//end function </script> <textarea id="myText"></textarea> <br> <button onclick="addOne();">Click Me!</button> // add one (increment) <script type="text/javascript"> function addOne(){ var curVal=document.getElementById('myText').innerHTML*1; document.getElementById('myText').innerHTML=curVal+1; }//end function </script> <textarea id="myText"></textarea> <br> <button onclick="addOne();">Click Me!</button> Like so? Link to comment https://forums.phpfreaks.com/topic/201483-ajax-and-php-change-text-field-with-a-button/#findComment-1057199 Share on other sites More sharing options...
sugarcube Posted May 12, 2010 Author Share Posted May 12, 2010 thank you so much, it meant the first one. Link to comment https://forums.phpfreaks.com/topic/201483-ajax-and-php-change-text-field-with-a-button/#findComment-1057219 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.