...

View Full Version : Alert box in drop down HTML



ba7159
10-19-2009, 07:52 PM
I'm taking an entry level CS course. While I realize this question is simple it goes past what our professor has taught this class. I've taken pascal, and C++ in highschool and I think I could do better than most of the clowns in here. If you don't want to give me the answer that's cool you'd rather pick my brain.

What i'm trying to do - ask the user a question. There's a drop down box that has possible answers. If they click on the right one I tell them via alert box. Else I tell them their answer was wrong.

Here's my script

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Writing Intervals</title>
</head>

<body>

There are two things to take into consideration when writing intervals. The first is the number, which is determined
by the distance between the letters. Here are some examples of this first part
<ul>
<li>C-C is a unison
<li>C-D is a second <em>think c(first) d (second)</em>
<li>C-E is a third <em>think c(first) d (second) e (third)</em>

<li>C-G is a fifth
<li>F-A is a third
</ul>

Let's see if you understand this. Here are some examples for you to try.

<ol>
<li>G to G would be a
<select>
<option>Unison</option>
<option>Second</option>
<option>Third</option>

<option>Fourth</option>
<option>Fifth</option>
<option>Sixth</option>
<option>Seventh</option>
</select>
<li>G to A would be a
<select>
<option>Unison</option>

<option>Second</option>
<option>Third</option>
<option>Fourth</option>
<option>Fifth</option>
<option>Sixth</option>
<option>Seventh</option>

</select>
<li>B to D would be a
<select>
<option>Unison</option>
<option>Second</option>
<option>Third</option>
<option>Fourth</option>
<option>Fifth</option>

<option>Sixth</option>
<option>Seventh</option>
</select>
<ol>

</body>
</html>

ba7159
10-19-2009, 07:54 PM
just noticed I didn't close out the ol tag at the end. I need to proof all this on my own, but if someone could help me with my question that would be cool.

djm0219
10-19-2009, 09:24 PM
To make it easier for us "clowns" to help you what have you tried that isn't working the way you want it to?

godofreality
10-20-2009, 07:26 AM
your issue your in need of help is a javascript deal basically u need to add an event to your <select> tags u being a c++ coder should know what an event is but basically u want


//use the onchange event to call up the getAnswer function created in javascript and give each <select> tag an id so the function knows which dropdown is sending the user answe from and add a value to each option so they have a value not sure how to put that lol and created a blank option as the default option

<select onchange="getAnswer(this)" id="1">
<option value=""></option>
<option value="unison">Unison</option>
<option value="second">Second</option>
<option value="third">Third</option>
<option value="fourth">Fourth</option>
<option value="fifth">Fifth</option>
<option value="sixth">Sixth</option>
<option value="seventh">Seventh</option>
</select>

<li>G to A would be a
<select onchange="getAnswer(this)" id="2">
<option value=""></option>
<option value="unison">Unison</option>
<option value="second">Second</option>
<option value="third">Third</option>
<option value="fourth">Fourth</option>
<option value="fifth">Fifth</option>
<option value="sixth">Sixth</option>
<option value="seventh">Seventh</option>
</select>

<li>B to D would be a
<select onchange="getAnswer(this)" id="3">
<option value=""></option>
<option value="unison">Unison</option>
<option value="second">Second</option>
<option value="third">Third</option>
<option value="fourth">Fourth</option>
<option value="fifth">Fifth</option>
<option value="sixth">Sixth</option>
<option value="seventh">Seventh</option>
</select>


and for the javascript


<script type="text/javascript">
function getAnswer(thisSelect)
{
with(thisSelect)
{
switch(id)
{
case 1:
//this is for question 1
if(value == "the correct answer"){ alert("Correct");}else{ alert("Incorrect");}
break;

case 2:
//question 2
if(value == "the correct answer"){ alert("Correct");}else{ alert("Incorrect");}
break;

case 3:
//question 3
if(value == "the correct answer"){ alert("Correct");}else{ alert("Incorrect");}
break;
}
}
}

Rowsdower!
10-20-2009, 01:07 PM
Durrrrrr! Me am big smart C++ man but me can't code dirt simple javascript. You am all dumb-dumb though!

Have a nice life with that attitude, cool guy! :thumbsup:

ba7159
10-22-2009, 08:40 PM
Durrrrrr! Me am big smart C++ man but me can't code dirt simple javascript. You am all dumb-dumb though!

Have a nice life with that attitude, cool guy! :thumbsup:

I'm not familiar with javascript. I may have given the wrong impression - I don't think C++ is more difficult than other languages...it's all about the nuances, the thought process is the same. Obviously I'm so inexperienced with javascript that I came here looking for help. Normally I can google my way out of problems. Yes it's dirt simple...one more trick to add to the bag.

ba7159
10-22-2009, 08:42 PM
Durrrrrr! Me am big smart C++ man but me can't code dirt simple javascript. You am all dumb-dumb though!

Have a nice life with that attitude, cool guy! :thumbsup:

Reread my post. Dude I'm saying the clowns in my class. This is an intro class - i'm trying to use it as an opportunity to get better.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum