text repeater

I am looking for a code that as you type text in one textbox, it will do the same in another field, but it needs to show as you type, so live update. does anyone have a code that does this?

so I found what I wanted,
[php]
If an item needs to be ordered, please enter their name here:

[/php] but now my problem is that I need multiple n2 textboxes because they are in a loop and they are separate forms, but I need them to have the same value there. any help?

Well, the easy way would be to use the “OnChange” option. When a user types the action would be sent to a routine that would copy the data into another field… Something like this:

<script type="text/javascript">
function textchanged(){
  var textTyped = document.getElementById('inputField').value;
  document.getElementById('outputField').value = textTyped;
}
</script>

<input ID="inputField" type="text" VALUE="Type something here..." ONKEYPRESS="textchanged();" />
<input ID="outputField" type="text" VALUE="..." size="50" />

I tested this and it works… Hope it helps…

I need multiple text boxes for it to repeat in though with the same name…how do I do this?

Just add as many fields as you need…

<script type="text/javascript">
function textchanged(){
  var textTyped = document.getElementById('inputField').value;
  document.getElementById('outputField1').value = textTyped;
  document.getElementById('outputField2').value = textTyped;
  document.getElementById('outputField3').value = textTyped;
  document.getElementById('outputField4').value = textTyped;
}
</script>

<input ID="inputField" type="text" VALUE="Type something here..." ONKEYPRESS="textchanged();" />
<input ID="outputField1" type="text" VALUE="..." size="50" />
<input ID="outputField2" type="text" VALUE="..." size="50" />
<input ID="outputField3" type="text" VALUE="..." size="50" />
<input ID="outputField4" type="text" VALUE="..." size="50" />

Or, you could put them into an array if needed… This would be trickier, but, depends on how many you need.
If a small number, I would use it this way as you can name the fields to make sense. I am curious what you need this for…

I would like to do the same basic thing now, but rather I would like to have a set price to start with. lets say $50. when I type in the 1st price lets say $20, I would like the 2nd field to autmatically fill in with the remainder, in this example, $30,. how would I do this?

Well, just do it. You should learn some basic Javascript. It works just like PHP only in the CLIENT-SIDE, just like HTML… So something like…

<script type="text/javascript">
function textchanged(){
  var textTyped = document.getElementById('inputField1').value;
  var texTyped2 = document.getElementById('inputField2').value;
  document.getElementById('outputField2').value = textTyped - textTyped2;
}
</script>

Basically, same as before, just doing the math… (I didn’t test it, but, should work.)

Sponsor our Newsletter | Privacy Policy | Terms of Service