Html and javascript. Radio buttons and text box?

Nonyabusiness

New member
So when someone click the radio button "Seattle" or "New York" i want a text to appear in the text box. So if they click Seattle, "The west coast" appears and when they click New York, "The east coast appears in the text box.
This is what i have so far...
<form action="">
<p>Tell me about yourself, what city do you prefer?</p>
<input type="radio" onclick="changeText(this)" name="radio" value="0"/>Seattle
<input type="radio" onclick="changeText(this)" name="radio" value="1"/>New York

<input type="text" name="city" />

</form>

<script type="text/javascript">
var text=new Array("The west coast" , "The east coast");

function changeText(radio)
{
document.getElementById( 'text').value = "" + text[radio.value];
}

</script>


How do i get it to work?
 
instead of just using input tags enclose them in a form tag, make sure to use the form attribute to give the form a name, then change your onclick handler code to look like this:

<input type="radio" onclick="formName.city.value='the west coast'" name="radio" value="0"/>Seattle
<input type="radio" onclick="formName.city.value='the east coast'" name="radio" value="0"/>Seattle

make sure to enclose the string values in single quotation marks, '
i should presume this would work.
 
Back
Top