faqts : Computers : Programming : Languages : JavaScript : Forms : SELECT

+ Search
Add Entry AlertManage Folder Edit Entry Add page to http://del.icio.us/
Did You Find This Entry Useful?

10 of 17 people (59%) answered Yes
Recently 7 of 10 people (70%) answered Yes

Entry

Drop down menu - how can I show an alert message with info and then redirect to URL if yes.

Mar 27th, 2005 01:14
Andrew D, Linda Turner,


Some thing like this should do it.

<script language=javascript>
// <!--
function showselect(){
  // value is the value inside <option value=''>
  a=document.f.sb.options[document.f.sb.selectedIndex].value ;
  // text is the bit between > </option>
  b=document.f.sb.options[document.f.sb.selectedIndex].text ;
  if (a){
    if (confirm('Are you sure you want '+ b + '?')){
      location.href='http://some.domain.com/url.htm?value=' + a;
    }
  }
}

// -->
</script>

<form name=f>
<select name=sb onchange='javascript:showselect();'>
<option value=''>--- Select Option ---</option>
<option value='1'>option 1</option>
<option value='2'>option 2</option>
<option value='3'>option 3</option>
<option value='4'>option 4</option>
</select>
</form>



I hope that helps :)

Cheers
cya
Andrew