Current location: Hot Scripts Forums » General Web Coding » JavaScript » Execute javascript function based on selected dropdown list value.


Execute javascript function based on selected dropdown list value.

Reply
  #1 (permalink)  
Old 02-25-04, 03:46 PM
TKOEHN5751 TKOEHN5751 is offline
New Member
 
Join Date: Sep 2003
Location: Arlington TX
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Execute javascript function based on selected dropdown list value.

I would like to use a dropdown list that would execute a different javascript funtion based on the value the user selected.

My first goal is if 1,2,3,4,or 5 is chosen the second field(named "Eway") appears. If 0 is chosen the field disappears.

My second goal is if the 2nd field is visable it needs to be required, when it is not visible it should NOT be required.

Here is what I've got so far...

<SCRIPT>
function yes() {
MMDiv.style.visibility='visible';
mainform.MakeModel.focus();
}</SCRIPT>
<SCRIPT>
function no() {
MMDiv.style.visibility='hidden';
mainform.MakeModel.focus();
}</SCRIPT>

<table width="292" align=center cellpadding=0 cellspacing=1 bgcolor=A4C0DD border=1><tr><td colspan="8">
<table border="0" align="center"><tr>

<td height=10 width="50"><B>Card 1</td>

<td>Qty
<select class=d type=text name=qty1 size=1 onchange="yes()">
<option selected value="0"></option>
<option onchange=yes() value="1">1 box of 250</option>
<option value="2">2 boxes of 250</option>
<option value="3">3 boxes of 250</option>
<option value="4">4 boxes of 250</option>
<option value="5">5 boxes of 250</option>
</td>

<td>
<DIV ID="MMDiv" style="visibility:hidden">
<LABEL FOR="MakeModel">Eway # <INPUT TYPE="TEXT" class="d" ID="MakeModel" name="requiredeway1" size="6">
</LABEL>
</DIV>
</td>

</tr></table>
</td></tr></table>
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #2 (permalink)  
Old 02-26-04, 07:38 AM
jimcart jimcart is offline
Newbie Coder
 
Join Date: Feb 2004
Posts: 18
Thanks: 0
Thanked 0 Times in 0 Posts
<HTML>
<HEAD>
<TITLE></TITLE>
<SCRIPT>
function show(aval) {
if (aval >= 1) {
MMDiv.style.visibility='visible';
mainform.MakeModel.focus();
} else
MMDiv.style.visibility='hidden';
}
</SCRIPT>
</HEAD>
<BODY>
<Form name="mainform">
<table width="292" align=center cellpadding=0 cellspacing=1 bgcolor=A4C0DD border=1><tr><td colspan="8">
<table border="0" align="center"><tr>
<td height=10 width="50"><B>Card 1</td>
<td>Qty
<select class=d type=text name=qty1 size=1 onchange="javascript:show(this.options[this.selectedIndex].value)">
<option selected value="0"></option>
<option onchange=yes() value="1">1 box of 250</option>
<option value="2">2 boxes of 250</option>
<option value="3">3 boxes of 250</option>
<option value="4">4 boxes of 250</option>
<option value="5">5 boxes of 250</option>
</td>
<td>
<DIV ID="MMDiv" style="visibility:hidden">
<LABEL FOR="MakeModel">Eway # <INPUT TYPE="TEXT" class="d" ID="MakeModel" name="requiredeway1" size="6">
</LABEL>
</DIV>
</td>
</tr></table>
</td></tr></table>
</form>
</BODY>
</HTML>
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #3 (permalink)  
Old 03-14-04, 01:13 AM
jahwz jahwz is offline
New Member
 
Join Date: Mar 2004
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Question

i made a few small changes to the script for what I needed, but even before changes mozilla firefox was giving errors that the id I am referencing wasn't defined.

the following code gives this error in the mozilla JS Console, but works fine in IE6 and Opera 7 without any errors, but no go in firefox or mozilla 1.6

Error: optionyes is not defined

note with the original code posted previously the error was 'MMDiv not defined'
Any ideas?

Code:
<html>
<head>
<title></title>
<SCRIPT>
function show(aval) {
if (aval == "Yes") {
optionyes.style.visibility='visible';
optionyes.style.display='block';
Form.fileURL.focus();
} 
if (aval == "No") {
optionyes.style.visibility='hidden';
optionyes.style.display='none';
}
}
</SCRIPT>
</head>
<body>
<form name="Form"> 
<div>
File Available:
<select name="file" onchange="java_script_:show(this.options[this.selectedIndex].value)">
<option value="No" selected="selected">No</option>
<option value="Yes">Yes</option>
</select>
</div>
<div id="optionyes" style="visibility:hidden">
URL: <input name="fileURL" size="40" />
</div>
</body>
</html>

Last edited by jahwz; 03-14-04 at 01:16 AM.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
execute php into javascript function Hagoromo PHP 3 05-23-07 03:19 AM
Classified Ads skipper23 Perl 2 12-30-03 04:43 AM
Declared Functions skipper23 PHP 4 12-17-03 11:06 AM
index page not showing up skipper23 PHP 3 12-15-03 02:10 PM
Help trim code down TheLaughingBandit JavaScript 0 09-02-03 10:50 AM


All times are GMT -5. The time now is 11:05 AM.
vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.