
May 18th, 2004, 07:22 PM
|
|
|
|
Join Date: Apr 2007
Location: UCONN, Storrs, CT
Posts: 15
Time spent in forums: < 1 sec
Reputation Power: 0
|
|
|
Calling Javascript functions from Events
Two questions.
1) How do I reference the current value of the <SELECT> object elsewhere in Javascript code?
2) How do I call a Javascript function from the 'onchange' event of a <SELECT> object?
Here's what my current (not-working) code looks like:
php Code:
Original
- php Code |
|
|
|
<!-- this code found in the <HEAD> --> <script type="text/javascript"> function hide(el) { document.getElementById(el).style.visibility="hidden"; } function show(el) { document.getElementById(el).style.visibility="visible"; } function hideshow(el) { if (document.getElementById(el).value="3") { show('Wbus'); // if William is selected, show('Wweb'); // show radio buttons show('Lbus'); // and labels show('Lweb'); } else { hide('Wbus'); // otherwise, hide('Wweb'); // hide radio buttons hide('Lbus'); // and labels hide('Lweb'); } } </script>
php Code:
Original
- php Code |
|
|
|
<!-- this code found in a <FORM>, within the <BODY> --> <select name="sendto" id="sendto" size="1" onchange="javascript:hideshow('sendto')"> <option value="1">Stewart <option value="2">Natalie <option value="3">William <option value="4">Jonathan </select> <input type="radio" name="Wsel" id="Wbus"><label for="Wbus" id="Lbus">Business</label> <input type="radio" name="Wsel" id="Wweb"><label for="Wweb" id="Lweb">Web Design</label>
I most likely need to replace:
(Question 1) if (document.getElementById(el).value="3")
(Question 2) onchange="javascript :hideshow('sendto')"
Thanks for your help.
|