Inputing value in a form using javascript

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • macintoshhondo
    New Member
    • Jan 2008
    • 1

    Inputing value in a form using javascript

    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"TA RGET="_blank">
    <input type="image" src="15623.jpg" style='cursor:p ointer; width: 45; height: 45;'>
    <input type='text box' name='content' value='Textfiel d' size="8">
    </form>[/HTML]

    FORM 3:

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

    FORM 4:

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

    FORM 5:

    [HTML]<td><form action='insert. asp' method="post"TA RGET="_blank">
    <input type="image" src="15623.jpg" style='cursor:p ointer; width: 45; height: 45;'>
    <input type='text box' name='content' value='Textfiel d +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
    Last edited by gits; Jan 5 '08, 12:53 PM. Reason: added code tags
  • gits
    Recognized Expert Moderator Expert
    • May 2007
    • 5390

    #2
    hi ...

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

    [CODE=javascript]function fill_inputs(nod e) {
    var val = parseInt(node.v alue);
    var inp = document.getEle mentsByTagName( 'input');

    for (var i = 0, item; item = inp[i]; i++) {
    if (item.type = 'text') {
    item.value = val + i;
    }
    }
    }
    [/CODE]
    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(thi s);") as the base-value

    kind regards

    Comment

    Working...