Click to See Complete Forum and Search --> : Reposted: Drop-downs & Iframes


mattdavid
01-17-2003, 07:33 PM
Sorry if anybody actually got to reply to my original post (I think I deleted it fast enough), but my problem's changed.

Anyways, I'm trying to use Javascripting with Drop-Down menus to load the links into an Iframe contained on the same page as the Drop-Down menus. I seem to be getting an error within the bolded line of my scripting, but I can't figure out what it is.

<SCRIPT LANGUAGE="JavaScript">
function LinkUp()
{
var number = document.DropDown.DDlinks.selectedIndex;
location.href = document.DropDown.DDlinks.options[number].value;
}
function acrossFrames()
{
if (document.DropDown.DDlinks.options[0].selected)
frames[0].location='cotd.html'
if (document.DropDown.DDlinks.options[1].selected)
parent.frames[0].location='cotw.html'
}
</SCRIPT>

And here is the form:
<FORM NAME="DropDown">
<SELECT NAME="DDlinks" onChange="LinkUp(this.form)">
<OPTION SELECTED> --> Pick One <--
<OPTION>Script Tip One
<OPTION>Script Tip Two
<OPTION>Script Tip Three
</SELECT>
<INPUT TYPE="HIDDEN" onClick="acrossFrames()">
</FORM>

I got all of the code from HTMLGoodies.com's "Script Tips" from appx. week 40 (I don't have the exact address anymore).

Again, I am grateful for any help. Thanks.

khalidali63
01-17-2003, 07:56 PM
Here try this.

cheers

Khalid


<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">

<html>
<head>
<title>Untitled</title>
</head>

<body>
<SCRIPT LANGUAGE="JavaScript">
var urls = new Array("http://www.java.sun.com",
"http://www.netscape.net",
"http://www.mozilla.org");
function LinkUp(){
var number = document.DropDown.DDlinks.selectedIndex;
index = parseInt(document.DropDown.DDlinks.options[number].value);
if(index!=-1){
ifr.document.location.href = urls[index]
}
}
function acrossFrames(){
if (document.DropDown.DDlinks.options[0].selected)
frames[0].location='cotd.html'
if (document.DropDown.DDlinks.options[1].selected)
parent.frames[0].location='cotw.html'
}
</SCRIPT>

And here is the form:
<FORM NAME="DropDown">
<SELECT NAME="DDlinks" onChange="LinkUp(this.form)">
<OPTION value="-1" SELECTED> --> Pick One <--
<OPTION value="0">Java Home Page
<OPTION value="1">Netscape Home Page
<OPTION value="2">Mozilla Home Page
</SELECT>
</FORM>
<iframe name="ifr" src="Blank.html" width="100%"></iframe>

</body>
</html>

mattdavid
01-18-2003, 11:46 AM
Arrgh. I tried the code and the error says:

'document.DropDown.DDlinks.selectedIndex' is null or not an object.

The line with the error is:

var number = document.DropDown.DDlinks.selectedIndex;

mattdavid
01-18-2003, 12:49 PM
Nevermind. I found out the problem. I was trying to use multiple drop-downs in my page, and I think that since they were all named the same, it didn't know which form does what.

Thanks a lot dude.