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!

Can't pass a value from a dropdown box to javascript 2

Status
Not open for further replies.

willz99ta

IS-IT--Management
Sep 15, 2004
132
US
Howdy and thanks for reading,

I am trying to display some html when a user selected a value in the drop down box. Right now it doesn't do anything. Any ideas?

Thank you for all of your help,
Will

Here is the code:

<select name="FollowUp" style='font-size:9pt' title='FollowUp'onChange="ShowFollowUp1(this.form.FollowUp)">
<option value='-NOT SELECTED-' >-Select-&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</option>
<option value=1>Email</option>
<option value=2>Phone</option>
<option value=3>Page</option>
</select>
<input type='radio' name='RentalLoc' value='Airport' onClick="ShowFollowUp1()">

<script type='text/javascript'>
<!--
function ShowFollowUp1(object)
{
FollowUp = object.options[object.selectedIndex].value
switch (FollowUp)
{
case 1:

Show1.innerHTML = ("<tr><td height='22' class='text2'>Email: <td/><input type='text2' id='Email' name='Email' size='20' maxlength='50' style='font-family:Verdana; font-size:7pt' title='Email' value='<%=strEmail%>'></tr>");
case 2:
Show1.innerHTML = ( "<tr><td height='22' class='text2'>Phone: <td/><input type='text2' id='Phone' name='Phone' size='20' maxlength='50' style='font-family:Verdana; font-size:7pt' title='Phone' value='<%=strPhone%>'></tr>" );
case 3:
Show1.innerHTML = ( "<tr><td height='22' class='text2'>Page: <td/><input type='text2' id='Page' name='Page' size='20' maxlength='50' style='font-family:Verdana; font-size:7pt' title='Page' value='<%=strPage%>'></tr>" );

}
}
//-->
</script>
<table>
<tr bgcolor='#EEEEEE'>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td colspan='4' class='text2' id='Show1'>

</td>
</tr>
</table>
 
Modify ShowFollowUp1() as follows. Notice '' around values in case.

<!--
function ShowFollowUp1(object)
{
FollowUp = object.options[object.selectedIndex].value
switch (FollowUp)
{
case '1':

Show1.innerHTML = ("<tr><td height='22' class='text2'>Email: <td/><input type='text2' id='Email' name='Email' size='20' maxlength='50' style='font-family:Verdana; font-size:7pt' title='Email' value='<%=strEmail%>'></tr>");
case '2':
Show1.innerHTML = ( "<tr><td height='22' class='text2'>Phone: <td/><input type='text2' id='Phone' name='Phone' size='20' maxlength='50' style='font-family:Verdana; font-size:7pt' title='Phone' value='<%=strPhone%>'></tr>" );
case '3':
Show1.innerHTML = ( "<tr><td height='22' class='text2'>Page: <td/><input type='text2' id='Page' name='Page' size='20' maxlength='50' style='font-family:Verdana; font-size:7pt' title='Page' value='<%=strPage%>'></tr>" );

}
}
//-->
 
Nope, I think there is still a problem. It is not diplaying the code.
 
To fix this I:

changed
<select name="FollowUp" style='font-size:9pt' title='FollowUp'onChange="ShowFollowUp1(this.form.FollowUp)">
to
<select name="FollowUp" style='font-size:9pt' title='FollowUp'onChange="ShowFollowUp1()">

and changed
function ShowFollowUp1(object)
{
FollowUp = object.options[object.selectedIndex].value
switch (FollowUp)
to
function ShowFollowUp1()
{
FollowUp = object.options[object.selectedIndex].value
switch (document.myForm.FollowUp.selectedIndex)



Thanks though for your help,
Will
 
Unless you want all 3 of your case statements to execute for option 1, or the last 2 for option 2, you'll need to put some 'break' statements in.

I suggest you look these up if you're not already of how they work, as they are quite paramount to 'switch' blocks.

Hope this helps,
Dan



Coedit Limited - Delivering standards compliant, accessible web solutions

Dan's Page [blue]@[/blue] Code Couch:
Code Couch Tech Snippets & Info:
 
(also I removed FollowUp = object.options[object.selectedIndex].value)
 
Some ideas:

1.-You're missing a lot of semicolons, although it may not be related to this.
2.- You're mixing single and double quotes: I'd check the generated HTML
3.-How do you acess Show1? That's not a global variable?
4.- Are you sure that's not throwing errors?



Cheers,
Dian
 
Whew! Yep, you guys were right -- the quotes and break statements were necessary to finally bring my script up to par. Thanks --- this was my first Java script work.
 
You're welcome!

star.gif
star.gif
star.gif
star.gif
star.gif


Dan






Coedit Limited - Delivering standards compliant, accessible web solutions

Dan's Page [blue]@[/blue] Code Couch:
Code Couch Tech Snippets & Info:
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top