Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

window.open URL parameter help 2

Status
Not open for further replies.

moirakris

Technical User
Oct 11, 2002
82
Ok I have the following script generously provided by webteacher.com but am trying to figure out how to modify it.

You select a catagory in the first drop down, and then the second drop down changes to show the correct sub catagories. Now what I want to add is a form button that when clicked opens a url based on the name in the sub catagory chosen +.html.

Example, if they choose Advisor in the catagory then Kel in the sub catagory, when they press the Get Info button I would like it to open a file named kel.html

Here is the code

<HTML>
<HEAD>
<SCRIPT LANGUAGE=&quot;JavaScript&quot;>
<!--Begin JavaScript


function setList(f) {
secondlist=eval(&quot;'&quot;+f.elements['main'].options[f.elements['main'].selectedIndex].text+&quot;'&quot;);
f.elements['sub'].options.length=0;
size=eval(&quot;lists['&quot;+secondlist+&quot;'].length&quot;);
for(i=0;i<size;i++) {
newval=eval(&quot;lists['&quot;+secondlist+&quot;']&quot;);
f.elements['sub'].options=new Option(newval);
};
f.elements['sub'].selectedIndex=0;
};
lists=new Array();
lists['Leader'] = new Array();
lists['Leader'][0]=&quot;Dennis&quot;;
lists['Leader'][1]=&quot;Carl&quot;;
lists['Leader'][2]=&quot;Kris&quot;;


lists['Council'] = new Array();
lists['Council'][0]=&quot;Charlie&quot;;
lists['Council'][1]=&quot;David&quot;;
lists['Council'][2]=&quot;Jay&quot;;


lists['Advisors'] = new Array();
lists['Advisors'][0]=&quot;Nicole&quot;;
lists['Advisors'][1]=&quot;Kel&quot;;
lists['Advisors'][2]=&quot;Andy&quot;;
lists['Advisors'][3]=&quot;Dan&quot;;


//End JavaScript-->
</SCRIPT>
<BODY BGCOLOR=WHITE onLoad=&quot;setList(document.listsform)&quot;>

<FORM NAME=&quot;listsform&quot;>
<SELECT NAME=&quot;main&quot; onChange=&quot;setList(form)&quot;>
<OPTION>Leader</OPTION>
<OPTION>Council</OPTION>
<OPTION>Advisors</OPTION>

</SELECT>

<SELECT NAME=&quot;sub&quot;>
<OPTION>       </OPTION>
<OPTION></OPTION>
<OPTION></OPTION>
<OPTION></OPTION>

</SELECT>

</FORM>
</BODY></HTML>


Any assistance would be greatly appreciated. I am just starting to learn this and really struggling with it Moira
&quot;Those that stop learning, stop living.&quot;
 
I rewrote the script -- hope that's ok
Code:
<script>
<!--
leaders = new Array();
leaders[0] = &quot;Dennis&quot;;
leaders[1] = &quot;Carl&quot;;
leaders[2] = &quot;Kris&quot;;

council = new Array();
council[0] = &quot;Charlie&quot;;
council[1] = &quot;David&quot;;
council[2] = &quot;Jay&quot;;

advisor = new Array();
advisor[0] = &quot;Nicole&quot;;
advisor[1] = &quot;Kel&quot;;
advisor[2] = &quot;Andy&quot;;
advisor[3] = &quot;Dan&quot;;

function getURL(f) {
	baseDir = &quot;[URL unfurl="true"]http://you.yourserver.com/&quot;;[/URL]
	selection = f.sub.options(f.sub.selectedIndex).text + &quot;.html&quot;;
	selection = selection.toLowerCase();
	window.open(baseDir + selection,&quot;&quot;);
}

function setList(f) {
		f.sub.remove(0);
	if (f.main.selectedIndex == 0) {
		for (i=0; i < leaders.length; i++) {
			f.sub.options[i] = new Option(leaders[i]);
		}
	} else if (f.main.selectedIndex == 1) {
		for (i=0; i < council.length; i++) {
			f.sub.options[i] = new Option(council[i]);
		}
	} else if (f.main.selectedIndex == 2) {
		for (i=0; i < advisor.length; i++) {
			f.sub.options[i] = new Option(advisor[i]);
		}
	}
}
//-->
</script>

<body onload=&quot;setList(listsform)&quot;>

<form name=&quot;listsform&quot;>

<select name=&quot;main&quot; onChange=&quot;setList(form)&quot;>
<option>Leader</option>
<option>Council</option>
<option>Advisors</option>
</select>

<select name=&quot;sub&quot;></select>

<br><br>

<input type=&quot;button&quot; value=&quot;Open URL&quot; onClick=&quot;getURL(form)&quot;>

</form>
 
Thank you so much! Works great. I am going to go pick it apart and hopefully learn from it. I **will** learn this stuff ....eventually lol

Moira
&quot;Those that stop learning, stop living.&quot;
 
Hmm ok this is strange. I added two more names to the leaders sub catagory. Now the leaders[4] Bill shows up in the browser under the Council sub catagory unless I refresh the page.... I do not get the error when going from the advisor to the leader or even from the advisor to the council. If you open the leader sub, then go to advisor sub then council sub, it displays correctly. Hope that made sense.

script is exacly the same as above except for leaders is now

leaders = new Array();
leaders[0] = &quot;Dennis&quot;;
leaders[1] = &quot;Carl&quot;;
leaders[2] = &quot;Kris&quot;;
leaders[3] = &quot;Bob&quot;;
leaders[4] = &quot;Bill&quot;; Moira
&quot;Those that stop learning, stop living.&quot;
 
Sorry I didn't know you were going to add more things to the array -- just a minor adjustment:
Code:
function setList(f) {
	for (i=0; i < 10; i++) {
        	f.sub.remove(i);
	}
    if (f.main.selectedIndex == 0) {
        for (i=0; i < leaders.length; i++) {
            f.sub.options[i] = new Option(leaders[i]);
        }
    } else if (f.main.selectedIndex == 1) {
        for (i=0; i < council.length; i++) {
            f.sub.options[i] = new Option(council[i]);
        }
    } else if (f.main.selectedIndex == 2) {
        for (i=0; i < advisor.length; i++) {
            f.sub.options[i] = new Option(advisor[i]);
        }
    }
}
I've just added the following code to the setList() function:
Code:
	for (i=0; i < 10; i++) {
        	f.sub.remove(i);
	}
What that will do is remove every <option> within the <select> tag. It will remove options 0 - 10 as you can see in the statement i < 10. Should you add more strings to any of the arrays, just make sure you change that statement accordingly. For example, if you have an array of 23 strings, make sure you change i < 10 to i < 23 or any number higher than 23. Options which do not exist will simply not be removed, and no errors will be raised. Should you need any more explained, just let me know -- I'm very happy to help :)
 
hehe I didn't know I was going to add more to it either, once I start playing around I never know what I might do (=

Thanks again for all your time and effort into assisting me with this! The ideas of what I can use it for are starting to flow. I have a gaming website for Diablo II LoD and this particular script will come in very handy for the members and quests section both.

Happy Holidays to you
Moira
&quot;Those that stop learning, stop living.&quot;
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top