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 bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Scripting form elements 1

Status
Not open for further replies.

Arion23

IS-IT--Management
Mar 29, 2001
132
AU
Hi all,

I apologise for asking what I'm sure is a very easy question to answer, but I am having a very "bad hair day" :p

I have a number of radio buttons and dropdown lists in a form, and I'm trying to find some simple code that will achieve the following effect:

If user makes a selection from dropdown A, Radio A becomes checked, if user makes a selection from dropdown B, then Radio B becomes checked.

Many thanks in advance...
 
Hi Arion23,

Put this script between the head:

Code:
<script language=&quot;JavaScript&quot;>
	function checkRadio(which) {
		document.form.radio[which].checked = true
	}
</script>

And this form in the body:

Code:
<form action=&quot;&quot; name=&quot;form&quot; method=&quot;post&quot;>
	<select name=&quot;dropa&quot; onChange=&quot;checkRadio(0)&quot;>
		<option selected>---</option>
		<option>line1</option>
		<option>line2</option>
	</select>
	<br>
	<select name=&quot;dropb&quot; onChange=&quot;checkRadio(1)&quot;>
		<option selected>---</option>
		<option>line1</option>
		<option>line2</option>
	</select>
	<br>
	<input type=&quot;radio&quot; name=&quot;radio&quot;>Radio A
	<br>
	<input type=&quot;radio&quot; name=&quot;radio&quot;>Radio B
</form>

This does the trick.

Hope it gets you started! :p

Kristof
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top