link from selection

Do you have a question? Post it now! No Registration Necessary.  Now with pictures!

Threaded View

Hi, I have a page with the following code.

<input type=button value="Show"

<select name="myselect">
<option value=1>1
<option vlaue=2>2
<option value=3>3

When use click the Show button, I would like to replace the XXX by the
selected number from the selection "myselect". Since there is a form
between <intput button> and the selection, I can not use form for the
Show button.

How can I write the onclick="location.href='



Re: link from selection wrote:
Quoted text here. Click to load it
typo?  :-)

Quoted text here. Click to load it

That would normally be done by putting the select in a form and
submitting it.  Any other solution will require scripting, which is not
really the topic of this group.

Quoted text here. Click to load it

Using script:

   <input type=button value="Show"

   <select name="myselect" id="myselect">
     <option value=1>1
     <option value=2>2
     <option value=3>3

   <script type="text/javascript">
   function changeHref()
     var val, o='';
     if ( document.getElementById
        && (o = document.getElementById('myselect'))){
       if ('select' == o.nodeName.toLowerCase()){
         val = o[o.selectedIndex].value;
     window.location = '' + val;

The script element can be put in the head to keep things tidy, the
script content can be put into an external file.  The usual caveats
apply - if scripting is not available or turned off, or required
features are not supported, the button does nothing.

If you have further questions, ask in comp.lang.javascript


Site Timeline