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

Inputing value in a form using javascript

P: 1
Hi !
i am a newbie and dont know javascript much. what i really need is a simple javascript code that can insert number in the value section of the different forms from the one form.

FORM 1:
[HTML]<form>
<input type="text" name="textField" size="20"><br>
</form>[/HTML]


In the "TextField " of Form 1 i type any number and let the number be 100. Now what i really want is that in Form 2 : Textfield should be 100 that is just like that of form 1. In Form 3 Textfield should be 101 (i.e 100+1 or Textfield +1 ). In form 4 Textfield should be 102 (I.e 100+2 or or Textfield +2). In form 5 the textfield should be 103 (i.e 100+3 or or Textfield +3). and so on upto FORM 11.

Here Textfield is supposed to be taken as 100. and it is what the user type in form 1.

FORM 2:

[HTML]<td><form action='insert.asp' method="post"TARGET="_blank">
<input type="image" src="15623.jpg" style='cursor:pointer; width: 45; height: 45;'>
<input type='text box' name='content' value='Textfield' size="8">
</form>[/HTML]

FORM 3:

[HTML]<td><form action='insert.asp' method="post"TARGET="_blank">
<input type="image" src="15623.jpg" style='cursor:pointer; width: 45; height: 45;'>
<input type='text box' name='content' value='Textfield + 1' size="8">
</form>[/HTML]

FORM 4:

[HTML]<td><form action='insert.asp' method="post"TARGET="_blank">
<input type="image" src="15623.jpg" style='cursor:pointer; width: 45; height: 45;'>
<input type='text box' name='content' value='Textfield +2' size="8">
</form>[/HTML]

FORM 5:

[HTML]<td><form action='insert.asp' method="post"TARGET="_blank">
<input type="image" src="15623.jpg" style='cursor:pointer; width: 45; height: 45;'>
<input type='text box' name='content' value='Textfield +3' size="8">
</form>[/HTML]

Can you please help me in telling the proper javascript that i should use for the variable Textfield. and how the above can be processed.

your kind help in this regard will be highly appreciated
Thank you
Jan 4 '08 #1
Share this Question
Share on Google+
1 Reply


gits
Expert Mod 5K+
P: 5,320
hi ...

you may use the onchange-event in your first textbox to start the filling of all other boxes ... call a function like this:

Expand|Select|Wrap|Line Numbers
  1. function fill_inputs(node) {
  2.     var val = parseInt(node.value);
  3.     var inp = document.getElementsByTagName('input');
  4.  
  5.     for (var i = 0, item; item = inp[i]; i++) {
  6.         if (item.type = 'text') {
  7.             item.value = val + i;
  8.         }
  9.     }
  10. }
  11.  
this assumes that there are no more textboxes on your page and uses the value of the given textbox (where you call the function with "onchange = fill_inputs(this);") as the base-value

kind regards
Jan 5 '08 #2

Post your reply

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