help: select box 'launch' menu

M

mark | r

im having trouble with a select box launch menu...

i need it to be activated by an onclick event by a button that isnt in the
form.
my scripts look like...

<SCRIPT>
function leapto()
{top.location=document.form['formtwo'].dest.options[myindex].value; }
</SCRIPT>

<form name="formtwo" action=""><SELECT NAME="dest" SIZE=1>
<option SELECTED VALUE="#">Regional Outlets</option>
<option VALUE="http://www.newmediadesigns.co.uk">link one</option>
<option VALUE="http://www.andel.co.uk">link two</option>
</SELECT></form>

<a href="javascript://" onClick="leapto()"><img src="images/b-go.gif"
width="64" height="40" alt="submit this search" class="imgover"
border="0"></a>
 
M

mark | r

i need it to be activated by an onclick event by a button that isnt in
the
form.
Why can't the button be in the form?
function leapto()
{top.location=document.form['formtwo'].dest.options[myindex].value; }
</SCRIPT>
<form name="formtwo" action=""><SELECT NAME="dest" SIZE=1>
<option SELECTED VALUE="#">Regional Outlets</option>
<option VALUE="http://www.newmediadesigns.co.uk">link one</option>
<option VALUE="http://www.andel.co.uk">link two</option>
</SELECT></form>

<a href="javascript://" onClick="leapto()"><img src="images/b-go.gif"
width="64" height="40" alt="submit this search" class="imgover"
border="0"></a>

So many things wrong with this in principle, before we even get to
your coding problem. It fails totally if JavaScript is not enabled.
The alt attribute is misleading (this is not a search). It looks like
a form but it's really just a user unfriendly way of rendering a list
of ordinary links.

Still, I doubt that you're interested in any of that. You just want a
quick fix to your superficial problems.

<script type="text/javascript">
function leapto() {
for (i=0; i < document.getElementById("dest").options.length; i++) {
if (document.getElementById("dest").options.selected == true) {
top.location=document.getElementById("dest").options.value;
}
}
return false;
}
</script>

<form action="navpage.html" method="get" onSubmit="return leapto()">
<SELECT id="dest" NAME="dest">
<option SELECTED VALUE="#">Regional Outlets</option>
<option VALUE="http://www.newmediadesigns.co.uk">link one</option>
<option VALUE="http://www.andel.co.uk">link two</option>
</SELECT>
</form>

<a href="navpage.html" onClick="return leapto();"><img
src="images/b-go.gif" width="64" height="40" alt="something
useful"></a>

The navpage.html should contain the same links as your dropdown but as
a standard list of links, so that users without JavaScript can still
get to the pages in question.



thanks ste'

thanks for the rescue! i appreciate your comments and think the work-around
is excellent.

mark
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top