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

hyperlink within <select ... <option 2

Status
Not open for further replies.

glendacom

MIS
Oct 23, 2002
36
0
0
US
Is there a way to make this code work as &quot;advertised&quot;. I want each option entry in a <select> list to include a hyperlink.

Code:
<html>
<head>
</head>
<body>
<select size=3>
  <option><a href=&quot;[URL unfurl="true"]http://www.somewhere&quot;>link1</a>label1</option>[/URL]
  <option><a href=&quot;[URL unfurl="true"]http://www.somewhere&quot;>link2</a>label2</option>[/URL]
  <option><a href=&quot;[URL unfurl="true"]http://www.somewhere&quot;>link3</a>label3</option>[/URL]
  <option><a href=&quot;[URL unfurl="true"]http://www.somewhere&quot;>link4</a>label4</option>[/URL]
</select>
</body>
</html>

This code works but the link1, link2, etc are NOT hyperlinks as I want.

Can this be done?
 
wjeres the .com? was there a function or go button that was associated with the script? _______________________________________________
[sub]{ str = &quot;sleep is good for you. sleep gives you the energy you need to function&quot;;
ptr = /sleep/gi;Nstr = str.replace(ptr,&quot;coffee&quot;);alert(Nstr); }[/sub]
_______________________________________________
for the best results to your questions: FAQ333-2924
Is your question a
 
also missing a form tag and the size is to ssmall but that may all be typo's

suggestion seeing as I don't think you can place links in the select form tag (and I couldn't get it to work [smile])
<script>
function go() {
var url = frm.sel.options[frm.sel.selectedIndex].value;
alert(url);
location.href=url;
}
</script>
<form name=&quot;frm&quot;>
<select name=&quot;sel&quot; size=4>
<option value=&quot;</select>
</form> _______________________________________________
[sub]{ str = &quot;sleep is good for you. sleep gives you the energy you need to function&quot;;
ptr = /sleep/gi;Nstr = str.replace(ptr,&quot;coffee&quot;);alert(Nstr); }[/sub]
_______________________________________________
for the best results to your questions: FAQ333-2924
Is your question a
 
my reply to your first response got lost so here it is again ...

There are no buttons ... no form. Putting it in a form is superfluous (in this case) since there is no requirement for submit or reset or anything buttons. The size is plenty big enough for the example and the is simply a place holder ... a real link (i.e. doesn't work either. There are no typos ... it is EXACTLY what I want to work. Can it be done?
 
Hi glendacom,

Do you mean something like this:

<html>
<head>
<script language=&quot;javascript&quot;>

function openWindow(url)
{
if (url !== &quot;none&quot;)
{
window.open(url, '','toolbar=yes, location=yes, directories=yes, status=yes, menubar=yes, resizable=yes, scrollbars=yes, top=0, left=0, height=600, width=800');
}
}

</script>
</head>
<body>
<SELECT name=&quot;selectboxname1&quot; ONCHANGE=&quot;javascript:eek:penWindow(selectboxname1.options[selectboxname1.selectedIndex].value);&quot; SIZE=&quot;1&quot;>
<OPTION value=&quot;none&quot; selected>- Select a Link -</OPTION>
<OPTION VALUE=&quot;<OPTION VALUE=&quot;</SELECT>
</body>
</html>

I didn't follow the discussion about the form/buttons but if you want to use a form then use someting like this:

<html>
<head>
<script language=&quot;javascript&quot;>

function openWindow(url)
{
if (url !== &quot;none&quot;)
{
window.open(url, '','toolbar=yes, location=yes, directories=yes, status=yes, menubar=yes, resizable=yes, scrollbars=yes, top=0, left=0, height=600, width=800');
}
}

</script>
</head>
<body>
<form name=&quot;MyForm&quot;>
<SELECT name=&quot;selectboxname2&quot; SIZE=&quot;1&quot;>
<OPTION value=&quot;none&quot; selected>-Select Here-</OPTION>
<OPTION VALUE=&quot;<OPTION VALUE=&quot;</SELECT><br><br>
<input type=&quot;submit&quot; value=&quot;go to link&quot; name=&quot;submit1&quot; ONCLICK=&quot;javascript:eek:penWindow(document.MyForm.selectboxname2.options[MyForm.selectboxname2.selectedIndex].value);&quot;>
</form>
</body>
</html>

Hope this helps,
Erik <-- My sport: Boomerang throwing !!
!! Many Happy Returns !! -->
 
Boomerang! YES! a star for you ... you deserve more! That is exactly what I was looking for. I had managed to get it to work with an onSubmit using a button but I didn't want a button. The OnChange works exactly like I wanted ... no button ... no form!

Thanks!
 
Hi guys,

No matter what way you use, if you want this to work cross-browser then you need to have <form> </form> tags.

Just simply adding <form> </form> around the first example boomerang suggested would at least make it work in the later versions of netscape.

It is not valid html to use a select box outside of a form.

Hope this helps Wullie


The pessimist complains about the wind. The optimist expects it to change.
The leader adjusts the sails. - John Maxwell
 
Good point, Wullie, but I'm one of those lucky (?) people that only has to target IE. It is absolutely impossible for my users to use Netscape. Would be good programming practice though to include the form tags.
 
Hi mate,

What about a few years down the line if a new version of IE decides that its not going to be so forgiving of html errors?

This is a simple step that only requires you to add 2 tags to your code, they will not make a difference to what your user sees, so I fail to see why there is any point in not including them.

Hope this helps Wullie


The pessimist complains about the wind. The optimist expects it to change.
The leader adjusts the sails. - John Maxwell
 
I agree ... and shall make an effort to start including them ... not including them is simply lazy programming habits which are very easy to fall into.
 
A star for Wullie for his effort to learn programmers to program the correct way! (I should have told the cross-browser info in my post)

Erik <-- My sport: Boomerang throwing !!
!! Many Happy Returns !! -->
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top