select onchange

driveflexfuel

New Member
Messages
159
Reaction score
0
Points
0
I am looking to use the code below on my website but I have not been able to figure out how to open the links in a new window. I do not mind if I have to use another language. If anyone can help me out I would highly appreciated.

Thanks

Code:
<form action="" id="sites">
<select name="sites" onchange='top.location.href=this.form.sites.options[this.form.sites.selectedIndex].value'> 

<option value="#">Select the site</option>
<option value="http://www.website1.com">website1</option>
<option value="http://www.website2.com">website2</option>
<option value="http://www.website3.com">website3</option>

</select>
</form>
 
Last edited:

freecrm

New Member
Messages
629
Reaction score
0
Points
0
I've figured a way to produce a jump menu with target = blank.

Shove this in your <head>

Code:
<script type="text/javascript">
function MM_jumpMenuNewWindow (selObj, restore) {
    window.open(selObj.options[selObj.selectedIndex].value);
    if (restore) selObj.selectedIndex=0;
}
</script>

Then the form

Code:
<form action="" id="sites">
  <select name="jumpMenu" id="jumpMenu" onchange="MM_jumpMenuNewWindow(this,0)">
    <option value="#">Select a Site</option>
    <option value="http://www.website1.com">website1</option>
    <option value="http://www.website2.com">website2</option>
    <option value="http://www.website3.com">website3</option>
  </select>
</form>

I've tested it and it works.
 

xPlozion

New Member
Messages
868
Reaction score
1
Points
0
or
Code:
<select name="sites" onchange='window.open(this.form.sites.options[this.form.sites.selectedIndex].value)'>

correct me if i'm wrong, but isn't MM_jumpMenuNewWindow a dreamweaver code snippet? i'm not attacking you if it is a dreamweaver snippet, but i am personally getting annoyed with people posting dreamweaver snippets... whatever happened to learning how to code, instead of using a program giving you a wizard and making code from that? another thing, the code snippet is more complex than the other code above.

again, i'm not attacking you, just pointing out a general trend going on...
 
Last edited:

driveflexfuel

New Member
Messages
159
Reaction score
0
Points
0
Freecrm that code would work but it throws all kinds of flags when using IE. I don't want my customers to have to click allow popups to view the content.

xPlozion That was exactly what I needed thanks
 
Last edited:

xPlozion

New Member
Messages
868
Reaction score
1
Points
0
np, dreamweaver tends to make things more complicated than they need to be.
 
Last edited:

freecrm

New Member
Messages
629
Reaction score
0
Points
0
or
Code:
<select name="sites" onchange='window.open(this.form.sites.options[this.form.sites.selectedIndex].value)'>

correct me if i'm wrong, but isn't MM_jumpMenuNewWindow a dreamweaver code snippet? i'm not attacking you if it is a dreamweaver snippet, but i am personally getting annoyed with people posting dreamweaver snippets... whatever happened to learning how to code, instead of using a program giving you a wizard and making code from that? another thing, the code snippet is more complex than the other code above.

again, i'm not attacking you, just pointing out a general trend going on...

Part of this is a DW snippet but as anyone knows who uses DW, it doesn't let you have target="_blank".

The script provided is an adaptation of the snippet to provide new window functionality.

It was just faster to do!
 

xPlozion

New Member
Messages
868
Reaction score
1
Points
0
i am aware that it doesn't let you use target blank, but at the same time, not does xhtml strict :p. i've been using that for a few years now, and have found basic ways to get around these minor issues.

for example, instead of using
Code:
<a href='http://www.x10hosting.com' target='_blank'>x10Hosting</a>
I would use
Code:
<a href='http://www.x10hosting.com' onclick='return externalUrl(this.href)'>x10Hosting</a>

and in my javascript functions file, i've got:
Code:
function externalUrl (href) {
  window.open(href);
  return false;
}

the return false would prevent the browser following that a href link in the current window, instead open it, leaving the current page in tact. if the user has javascript disabled, it would just follow the current link in the same tab/window ;)

again, not attacking you, but some of the things dw does, and many web designers do is down right sloppy (including huge sites, such as gamespot, xbox.com, etc...)
 

freecrm

New Member
Messages
629
Reaction score
0
Points
0
again, not attacking you, but some of the things dw does, and many web designers do is down right sloppy (including huge sites, such as gamespot, xbox.com, etc...)

No offence taken. I've only been developing for about 12 months so I am stretched between having to reach deadlines and understanding what I'm doing!

I've generally found that now I'm reaching the limits of what DW can achieve, I'm starting to learn! ;)

Maybe I should go back to notepad!
 

natsuki

New Member
Messages
112
Reaction score
0
Points
0
I think also use window.open(blah); return false; so it will just open a new window and do nothing with the original one
 

xPlozion

New Member
Messages
868
Reaction score
1
Points
0
I think also use window.open(blah); return false; so it will just open a new window and do nothing with the original one
yea, but it was cleaner and easier to write w/ the way i had it. also, if i want to change how the code works later down the road, i don't have to go to every link and modify it.
 
Top