Forum Moderators: open

Message Too Old, No Replies

Form select to target iframe

Load page into iframe when selected by drop down box

         

mrnoisy

4:16 am on Jul 9, 2003 (gmt 0)

10+ Year Member



I've got a page with a drop down box, and I want to send a page to an iframe depending on what option is selected.
I found the following code, but it doesn't work in Mozilla, which is what I'm using. Any help/suggestions would be appreciated.

<html>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<SCRIPT LANGUAGE="JavaScript">
function formHandler(form){
var URL = document.form1.site.options[document.form1.site.selectedIndex].value;
parent.main.location = URL;
}
</SCRIPT>

</head>

<body bgcolor="#FFFFFF" text="#000000">
<form name="form1">
<select name="site" size=1>
<option value="http://www.google.com">Horse Racing Specials
<option value="SoccerSpecials.php">Soccer Specials
<option value="golfspecials.php">Golf Specials
<option value="otherspecials.php">Other Specials
</select> <input type=button value="Go" onClick="java script:formHandler(this)"></form>
<IFRAME SRC="welcome.html" name="main" WIDTH=600 HEIGHT=320 frameborder=1 border=1></IFRAME>
</body>
</html>

korkus2000

12:29 pm on Jul 9, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



You have a space in between javascript here:

onClick="java script:formHandler(this)"

This can cuase problems. Have you tried it without the "javascript:". "javascript:" is usually used for href attributes to designate that it is not calling a new page but executing a javascript.

mrnoisy

12:58 pm on Jul 9, 2003 (gmt 0)

10+ Year Member



Thank you korkus2000 for that wonderfully simple solution to my problem.
One more question, how do I accomplish the same thing without the GO button?

korkus2000

1:05 pm on Jul 9, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Put this in the select tag:

onChange="formHandler(this)"

This will run your function when the select box has changed to a new value.