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 Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Drop down menu -> open (parent/blank) 1

Status
Not open for further replies.

DimisD

Technical User
Feb 7, 2007
15
GR
Hi there,

I have two drop down menus in a form. Onew for the "action" and the other for the "target".
Somewhere in the code below is wrong and the script doesn't function.
Can somebody help??

thank you


<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Untitled Document</title>
<script>

function jump()
{
if (form1.choice.options[choice.selectedIndex].value == "aaa.html"
(form1.action.value="aaa.html");
else
form1.action.value="bbb.html";

if (form1.open_win.options[open_win.selectedIndex].value == "_parent")
target=_parent;
else
(target=_blank);

</script>
</head>

<body>
<form name="form1" action="" method="post">

<select name="choice" size="1">
<option value="">CHOOSE A LINK</option>
<option value="aaa.html">AAA</option>
<option value="bbb.html">BBB</option>
</select>

<input TYPE="button" VALUE="GO!" onClick="jump()">

<select name="open_win" size="1">
<option value="_parent" selected>Current window</option>
<option value="_blank">New window</option>
</select>
</form>

</body>
</html>
 
Well DimisD, you didnt say what it is you expect your code to do. But let me guess. You wish to submit the form when the Go! button is clicked.

I dont think the button type of field submits when it is clicked. The idea with a button, I believe, is to write an event handler to do something more or different than submitting the form.

If by chance you wished to submit the form then the event handler script, jump(), would contain the following statement.
Code:
form1.submit();
 
Hi rac2,

What i want, is when pressing button "Go", to go to the Selected address + in the Selected target.

I put another unsuccesfull way i have tried to do it:


<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>SelectedIndex [file + target]</title>
<SCRIPT LANGUAGE=javascript>
function go() {
location=document.form1.menu.options[document.form1.menu.selectedIndex].value;
target=document.form1.menu2.options[document.form1.menu2.selectedIndex].value;
}
</SCRIPT>
</head>

<body>
<form name="form1" >
<select style="font-size:12px;color:#006699;font-family:verdana;background-color:#ffffff;" name="menu">
<option value=" selected>Gooooogleit</option>
<option value="</select>
<input style="font-size:12px;color:#ffffff;font-family:verdana;background-color:#006699;" type="button" onClick="go()" value="Go">
<p>&nbsp;</p>

<select style="font-size:12px;color:#006699;font-family:verdana;background-color:#ffffff;" name="menu2">
<option value="_parent" selected>parent</option>
<option value="_blank">blank</option>
</select>

</form>

</body>
</html>
 
This will get you what you want (tested), and it doesn't involve any forms at all:

Code:
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Untitled Document</title>
<script type="text/javascript">

function jump(urlAdd, winLoc) {
   if (urlAdd != "") {
      window.open(urlAdd, winLoc, '');
   }   
}     
</script>
</head>
<body>
   <select id="urlAddress" name="choice" size="1">
      <option value="">CHOOSE A LINK</option>
      <option value="[URL unfurl="true"]http://www.google.com">Google</option>[/URL]
      <option value="[URL unfurl="true"]http://www.msn.com">MSN</option>[/URL]
   </select>
   <input type="button" value="GO!" onclick="jump(document.getElementById('urlAddress').value, document.getElementById('windowLocation').value)">
   <select id="windowLocation">
      <option value="_parent" selected>Current window</option>
      <option value="_blank">New window</option>
   </select>
</body>
</html>

[small]"I see pretty girls everywhere I look, everywhere I look, everywhere I look. - Band song on movie "The Ringer"[/small]
<.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top