By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,940 Members | 1,250 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,940 IT Pros & Developers. It's quick & easy.

add text to textfield and/or textarea

P: 5
Hi there!

Im making a little project that uses while loop.
Here is my code:
Expand|Select|Wrap|Line Numbers
  1. <script type="text/javascript">
  2.  
  3. var counter = 0;
  4. var koniec = 100;
  5.  
  6. while(counter <= koniec) {
  7.         document.write(counter);
  8.         document.write(linebreak);
  9.         counter++;
  10.     }
  11. </script>
  12.  
I want the while loop to output numbers in a textfield. Ive done this by using "document.myForm.myText.value = counter",
but it only shows the final number ( in this case 100) and I want it to show al the progress like that:

https://www.youtube.com/watch?v=WfVNUpuVYkY&feature=plcp

Thanks a lot.
Aug 21 '12 #1
Share this Question
Share on Google+
3 Replies


gits
Expert Mod 5K+
P: 5,390
sure:

Expand|Select|Wrap|Line Numbers
  1. textfield.value = counter;
simply overwrites the value of the textfield. i assume you want to use a multiline textarea and it should look more like:

Expand|Select|Wrap|Line Numbers
  1. textarea.value += '\n' + counter;
which should append a linebreak and the next value to the textarea.
Aug 21 '12 #2

P: 5
thanks, seems working but I am not using a textarea I am using an textfield and I want to display just the current number not every one with enter :/

thanks anyway :)
Aug 21 '12 #3

gits
Expert Mod 5K+
P: 5,390
then the shown requirement when following the link in the original post is just misleading and the question was not clear enough.
Aug 22 '12 #4

Post your reply

Sign in to post your reply or Sign up for a free account.