JodyFischer
asked on
Select Statement with Javascript
I am writing an ASP page that needs to provide a definition depending on what the user selects.
Example -
<select name="fruit">
<option value="">Please Select</option>
<option value="Apple">Apple</optio n>
<option value="Orange">Orange</opt ion>
</select>
Depending on which fruit they select, a little window pops up with definition. How do I do this?
Example -
<select name="fruit">
<option value="">Please Select</option>
<option value="Apple">Apple</optio
<option value="Orange">Orange</opt
</select>
Depending on which fruit they select, a little window pops up with definition. How do I do this?
JodyFischer,
I used an "alert" but you could make a popup or have the definition appear in some "popup div" on the page. The alert part can easily be changed to something else but the rest will show you how to do the Javascript part.
Let me know if you have a question.
b0lsc0tt
I used an "alert" but you could make a popup or have the definition appear in some "popup div" on the page. The alert part can easily be changed to something else but the rest will show you how to do the Javascript part.
Let me know if you have a question.
b0lsc0tt
try something like this
function vag (obj) {
if (obj.value)=='Apple' {
alert ('Apple');
}
if (obj.value)=='Orange'{
alert ('Orange');
}
}
<select name="fruit" onchange="vag (this);">
<option value="">Please Select</option>
<option value="Apple">Apple</optio n>
<option value="Orange">Orange</opt ion>
</select>
function vag (obj) {
if (obj.value)=='Apple' {
alert ('Apple');
}
if (obj.value)=='Orange'{
alert ('Orange');
}
}
<select name="fruit" onchange="vag (this);">
<option value="">Please Select</option>
<option value="Apple">Apple</optio
<option value="Orange">Orange</opt
</select>
ASKER
It works as an alert, but I need it to be a small second browser. Can you show me how to do that instead?
what do you mean by that
ASKER
You wrote
I used an "alert" but you could make a popup or have the definition appear in some "popup div" on the page. The alert part can easily be changed to something else but the rest will show you how to do the Javascript part.
How do you make it a pop up (so it looks like a second browser window) instead of a grey box. I need to be able to format and have multiple lines on what comes up.
I used an "alert" but you could make a popup or have the definition appear in some "popup div" on the page. The alert part can easily be changed to something else but the rest will show you how to do the Javascript part.
How do you make it a pop up (so it looks like a second browser window) instead of a grey box. I need to be able to format and have multiple lines on what comes up.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
then you can try something like this
http://www.malsup.com/jquery/block/#page
http://www.malsup.com/jquery/block/#page
ASKER
I am so sorry to be a pain, but it's giving me an error - Access Denied
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>Untitled</title>
<script type="text/javascript">
function showDef(val) {
switch (val) {
case "Apple":
makeWin('A red fruit.');
break;
case "Orange":
makeWin('An orange colored fruit.');
break;
}
}
function makeWin(str) {
var w = window.open('','window1');
w.document.write("<html><h ead><title ></title>< /head>");
w.document.write("<body>" + str + "</body></html>");
w.document.close;
}
</script>
</head>
<body>
<select name="fruit" onchange="showDef(this.val ue);">
<option value="">Please Select</option>
<option value="Apple">Apple</optio n>
<option value="Orange">Orange</opt ion>
</select>
</body>
</html>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>Untitled</title>
<script type="text/javascript">
function showDef(val) {
switch (val) {
case "Apple":
makeWin('A red fruit.');
break;
case "Orange":
makeWin('An orange colored fruit.');
break;
}
}
function makeWin(str) {
var w = window.open('','window1');
w.document.write("<html><h
w.document.write("<body>" + str + "</body></html>");
w.document.close;
}
</script>
</head>
<body>
<select name="fruit" onchange="showDef(this.val
<option value="">Please Select</option>
<option value="Apple">Apple</optio
<option value="Orange">Orange</opt
</select>
</body>
</html>
ASKER
I closed everything and it's working great. Thank you so much.
Your welcome! I'm glad I could help. Thanks for the grade, the points and the fun question.
bol
bol
By the way, to improve the script and handle if the window already exists you could use ...
<script type="text/javascript">
var w = null;
function showDef(val) {
switch (val) {
case "Apple":
makeWin('A red fruit.');
break;
case "Orange":
makeWin('An orange colored fruit.');
break;
}
}
function makeWin(str) {
if (w== null || w.closed) {
w = window.open('','window1');
}
w.document.write("<html><h ead><title ></title>< /head>");
w.document.write("<body>" + str + "</body></html>");
w.document.close;
}
</script>
That change just makes sure the popup window doesn't exist or has been closed.
bol
<script type="text/javascript">
var w = null;
function showDef(val) {
switch (val) {
case "Apple":
makeWin('A red fruit.');
break;
case "Orange":
makeWin('An orange colored fruit.');
break;
}
}
function makeWin(str) {
if (w== null || w.closed) {
w = window.open('','window1');
}
w.document.write("<html><h
w.document.write("<body>" + str + "</body></html>");
w.document.close;
}
</script>
That change just makes sure the popup window doesn't exist or has been closed.
bol
You can do that with something like ...
<script type="text/javascript">
function showDef(val) {
switch (val) {
case "Apple":
alert('A red fruit.');
break;
case "Orange":
alert('An orange colored fruit.');
break;
}
}
</script>
The code above would go in the head section of your html. The select tag would become ...
<select name="fruit" onchange="showDef(this.val
Let me know if you have any questions or need more information.
b0lsc0tt