Select Box - Javascript

They have: 330 posts

Joined: Apr 2000

How would I write code that does the following?

If the radio button named Radio1 is clicked then select box named Select1 changes it's value to NewValue.

I don't know how to do this with Radio buttons or select boxes. Any help would be great.

Vincent Puglia's picture

They have: 634 posts

Joined: Dec 1999

Hi artsapimp,

Is this what you mean?

New Value
Old Value

Select
new Value
old Value

<script>
function doIt(fldVal, selObj)
{
for (i = 0; i < selObj.length; i++)
if (selObj.options[i].value == fldVal)
selObj.options[i].selected = true;
}
</script>

Note: if you want to use a button (instead of the onClick handler), you would need to loop through the radio button array and find the one that's checked

Vinny

Where the world once stood
the blades of grass cut me still

Want to join the discussion? Create an account or log in if you already have one. Joining is fast, free and painless! We’ll even whisk you back here when you’ve finished.