Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

newbee question want to set a value of text box to the value of a rb

Status
Not open for further replies.

toptomato

Programmer
Jul 22, 2005
62
US
hi,
i am trying to set a value of a text box to the value of the radio button when radio button is click. below is what i am trying to do:
<script type="text/JavaScript" >
function SetValue(of, to)
{
if (document.getElementById(of) != null && document.getElementById(to) != null)
{
document.getElementById(of).value = document.getElementById(to).value;
}
}
</script>

<input id="rb1" name="rb1" onclick="SetValue('tb1', 'rb1');" type="radio" value="color" />
 
I'd dispense with the function altogether and go with something this:

Code:
<input id="rb1" name="rb1" onclick="this.form.elements['tb1'].value = this.value;" type="radio" value="color" />

If you prefer using a function, consider something like this:

Code:
function SetValue(of, to) {
	to.form.elements[of].value = to.value;
}

...

<input id="rb1" name="rb1" onclick="SetValue('tb1', this);" type="radio" value="color" />

Hope this helps,
Dan

Coedit Limited - Delivering standards compliant, accessible web solutions

[tt]Dan's Page [blue]@[/blue] Code Couch
[/tt]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top