Click to See Complete Forum and Search --> : Setting a value in a text box


Rae12345
04-11-2003, 10:08 AM
I am trying to set a text box value on a form based on the value of anotther text box


User selects a date ( the value of this field is the name of the field that I want to set)

So I get the value of the field (value could be 1 for example) and put it in a variable

Now I must find the text box on the form that has a name equal to the variable.

How do I do this? Any help would be appreciated.

AdamGundry
04-11-2003, 10:32 AM
You can use document.getElementById, like this:

<input type="text" id="TextBox" name="TextBox">

<script type="text/javascript">
var box = "TextBox";

document.getElementById(box).value = 'Hello';
</script>


Adam

havik
04-11-2003, 10:46 AM
Do you want it to update automatically?
If so, try this code:

<form name=formname>

<input type=text name=box1 size=20>

<input type=text name=box2 size=20 onKeyUp=document.formname.box1.value=this.value>

</form>

type into the second box and the first box will update automatically.

But I'm not really sure what your asking.
use this to get the value of textboxes:
var example = document.nameofyourform.nameofthebox.value;

Hope that helps

Havik

Rae12345
04-11-2003, 12:48 PM
Thank you Adam, it worked like a charm.