Click to See Complete Forum and Search --> : link in dropdown menu not working
fablebad
10-07-2005, 08:03 PM
i have a dropdown menu that goes like this:
<script language="JavaScript" type="text/JavaScript">
<!--
<SCRIPT TYPE="text/javascript">
<!--
function dropdown(mySel)
{
var myWin, myVal;
myVal = mySel.options[mySel.selectedIndex].value;
if(myVal)
{
if(mySel.form.target)myWin = parent[mySel.form.target];
else myWin = window;
if (! myWin) return true;
myWin.location = myVal;
}
return false;
}
//-->
</SCRIPT>
<FORM
ACTION="../cgi-bin/redirect.pl"
METHOD=POST onSubmit="return dropdown(this.gourl)">
<div align="center">
<INPUT TYPE=SUBMIT VALUE="Check">
<select name="select" size="1" style="background-color:#E1D193" onChange="displaydesc(document.form1.select1, thetext1, 'textcontainer1')">
<option value="" selected>Choose A F2P Quest </option>
<option value="Quests/BFK.htm">Black Knight's Fortress - 2</option>
</select>
</div>
</FORM>
but when i select "Black Knight's Fortress - 2" and then click on check, it links to "file/.../cgi-bin/redirect.pl" instead of "file/.../quests/BFK.htm"
how come?? can anybody help me?
the htm file linked by the dropdown menu is located in a subfile in the file where the htm file containing the menu is... (crystal clear?)
Nedals
10-07-2005, 09:42 PM
I don't understand what you are trying to do with the dropdown function. It looks like you are attempting to display the content in a different window.
Dealing solely with the problem you posted...
<script type="text/javascript">
<!--
function dropdown() {
// Here to display form action only
// delete this function and the .....onsubmit="return dropdown() unless you use it for somthing else.
alert(document.forms[0].action);
return false;
}
//-->
</script>
</head>
<body>
<FORM ACTION="../cgi-bin/redirect.pl" METHOD=POST onSubmit="return dropdown()">
<div align="center">
<INPUT TYPE=SUBMIT VALUE="Check">
<select name="select" size="1" style="background-color:#E1D193" onchange="this.form.action = this.value">
<option value="../cgi-bin/redirect.pl" selected>Choose A F2P Quest </option>
<option value="Quests/BFK.htm">Black Knight's Fortress - 2</option>
</select>
</div>
</FORM>
</body>
</html>
fablebad
10-07-2005, 10:14 PM
it doesn't work. i copy the 2 codes in their respective sections and when i try the selection, a window popup saying something about my localhost.
another question, in javascript, how do i set the menu width, and can i align center the options of the menu? (how?)
Nedals
10-07-2005, 11:24 PM
The code I posted works but all it does is display the 'form action'. As I stated previously, I have no idea what you are trying to do with YOUR 'dropdown' function.
I assume you mean the <select> when you mention 'menu'
add width:200px or whatever to the style.
As far as I know, you cannot center the option text.
fablebad
10-07-2005, 11:35 PM
thx for the width thing
ill explain the whole thing of my dropdown (i may have a completely wrong code...)
i want the user to scroll the menu, select the option, then click "check" then the wanted page displays in the same window, in place of the previous page with the menu.
is that clearer?? thanks already
Nedals
10-08-2005, 02:17 AM
...wanted page displays in the same window, in place of the previous page with the menu.
Then use the HTML as I posted but REMOVE the onSubmit="return dropdown()" in the form tag and remove ALL the javascript from the <head> section and it will work as you state above. Pretty simple. :)
Let me explain...
.... onchange="this.form.action = this.value"
This bit of code will change the form 'action' setting it to the page defined by the 'selected' option value. Then, when you click 'Check', the submit event, the form will be posted to the 'action' page. No other coding required.
fablebad
10-08-2005, 12:06 PM
THX it works!!!
another thing, when i put width:200px in the style thingy, it doesn't work...i already have a style tag for my menu background color.
Nedals
10-08-2005, 12:11 PM
you mean all that??:
Yes.
fablebad
10-08-2005, 12:27 PM
nevermind, i left the code and it works anyway :) . i edited the post above, there is my other problem. can i have a background color AND a set width?
Nedals
10-08-2005, 12:31 PM
nevermind, i left the code and it works anyway :) . i edited the post above, there is my other problem. can i have a background color AND a set width?
1. The code's not needed. It just doesn't do anything if you leave it in.
2. Sure
style="width:200px; background-color:#E1D193"
UPDATE
Don't forget the semicolon.
Please don't edit your post after you get a reply. It tends to destroy the flow of the thread. If you must edit the post, do it with an update like this one.
for example:
In your edited post, add 'deleted block of javascript code';
fablebad
10-08-2005, 01:49 PM
ohh so the magic trick is that --> ";" !! :) i had tried with a simple comma...
ok, i'll follow those editing rules !
thx again, you've been of great help!