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 Quote Link to comment 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? Quote Link to comment 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? Quote Link to comment 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. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.