![]() |
|
||||||||||
![]() |
![]() |
![]() |
![]() |
![]() |
![]() |
![]() |
|||||
|
|
#1 |
|
WLC Member
Join Date: Jan 2010
Posts: 28
|
Hi Guys, I'm back... I'm going to get this Javascript stuff figured out yet!
Code:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/Transitional.dtd">
<html>
<head>
<title>Switch Statment</title>
<script language="javascript" type="text/javascript">
grade = document.frmOne.gradeScore.value
switch(grade){
case '1': alert('Congratulations! Your Grade is an "A!"');break;
case '2': alert('Your Grade is a "B"');break;
case '3': alert('Your Grade is a "C"');break;
case '4': alert('Your Grade is a "D"');break;
case '5': alert('Your Grade is a "F"');break;
case '6': alert('Your Grade is a "G"');break;
default:break;
}
</script>
</head>
<body>
<form name="frmOne" id="frmOne">
<select name="gradeScore">
<option value="">Please Select Your Score</option>
<option value="1">90 to 100</option>
<option value="2">80 to 89</option>
<option value="3">70 to 79</option>
<option value="4">60 to 69</option>
<option value="5">50 to 59</option>
<option value="6">Below 50</option>
</select></form>
</body>
</html>
Last edited by meesa; 8th February 10 at 07:56 PM. Reason: Added [code] Tags |
|
|
|
|
|
#2 |
|
WLC Mod
Join Date: Jul 2009
Location: Milky Way Galaxy
Posts: 1,602
|
You're running your code before the form loads. Put the JS after the form and it will work.
__________________
Romans 3:23 KJV - For all have sinned, and come short of the glory of God; Romans 6:23 KJV - For the wages of sin is death; but the gift of God is eternal life through Jesus Christ our Lord. Do you have the gift of God? I do! |
|
|
|
|
|
#3 |
|
WLC Member
Join Date: Jan 2010
Posts: 28
|
I tried this and it didn't work...where am I going wrong this time?
Code:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/Transitional.dtd">
<html>
<head>
<title>Switch Statment</title>
</head>
<body>
<form name="frmOne" id="frmOne">
<select name="gradeScore">
<option value="">Please Select Your Score</option>
<option value="1">90 to 100</option>
<option value="2">80 to 89</option>
<option value="3">70 to 79</option>
<option value="4">60 to 69</option>
<option value="5">50 to 59</option>
<option value="6">Below 50</option>
</select></form>
<script language="javascript" type="text/javascript">
grade = document.frmOne.gradeScore.value;
switch(grade){
case '1': alert('Congratulations! Your Grade is an "A!"');break;
case '2': alert('Your Grade is a "B"');break;
case '3': alert('Your Grade is a "C"');break;
case '4': alert('Your Grade is a "D"');break;
case '5': alert('Your Grade is a "F"');break;
case '6': alert('Your Grade is a "G"');break;
default:break;
}
</script>
</body>
</html>
Last edited by meesa; 8th February 10 at 08:19 PM. Reason: Added [code] Tags |
|
|
|
|
|
#4 |
|
WLC Mod
Join Date: Jul 2009
Location: Milky Way Galaxy
Posts: 1,602
|
What is it doing?
__________________
Romans 3:23 KJV - For all have sinned, and come short of the glory of God; Romans 6:23 KJV - For the wages of sin is death; but the gift of God is eternal life through Jesus Christ our Lord. Do you have the gift of God? I do! |
|
|
|
|
|
#5 |
|
WLC Member
Join Date: Jan 2010
Posts: 28
|
The form shows up, but it doesn't react to when I select a value
|
|
|
|
|
|
#6 |
|
WLC Mod
Join Date: Jul 2009
Location: Milky Way Galaxy
Posts: 1,602
|
Try alerting grade. Make sure it's getting the value.
__________________
Romans 3:23 KJV - For all have sinned, and come short of the glory of God; Romans 6:23 KJV - For the wages of sin is death; but the gift of God is eternal life through Jesus Christ our Lord. Do you have the gift of God? I do! |
|
|
|
|
|
#7 |
|
WLC Member
Join Date: Jan 2009
Posts: 7
|
You need to run the script when the select changes so something like this should do.
HTML Code:
<select name="gradeScore" onchange="findGrade(this.value)"> ... </select> <script language="javascript" type="text/javascript"> function findGrade(grade){ switch(grade){ case '1': alert('Congratulations! Your Grade is an "A!"');break; ... default:break; } } </script> Alternatively you could use HTML Code:
<select onchange="alert(this.value)"> <option value='Congratulations! Your Grade is an "A!"'>90 to 100</option> <option value='Your Grade is a "B"'>80 to 89</option> <option value='Your Grade is a "C"'>70 to 79</option> <option value='Your Grade is a "D"'>60 to 69</option> <option value='Your Grade is a "F"'>50 to 59</option> <option value='Your Grade is a "G"'>Below 50</option> </select> However this may mess up any form handling that you have in place
__________________
To view links or images in signatures your post count must be 5 or greater. You currently have 0 posts. |
|
|
|
![]() |
| Thread Tools | |
| Display Modes | |
Linear Mode |
|
|