Subject: onselect
Posted By: crmpicco Post Date: 1/26/2005 11:35:10 AM
<select name="book_date" id="book_date">
<option value="0">Today</option>
<option value="1">1 day ago</option>
<option value="2">2 days ago</option>
<option value="3">3 days ago</option>
<option value="4">4 days ago</option>
</select>

when a value from this drop-down box is selected, i want to go straight to the next page - display_bookings.asp.

what is the syntax for the onselect?

Thanks folks.

Picco

Reply By: ChrisScott Reply Date: 1/26/2005 11:39:17 AM
When the selection changes, the onchange event is fired.

HTH,

Chris

Reply By: crmpicco Reply Date: 1/26/2005 11:42:41 AM
<select name="book_date" id="book_date" onChange="display_bookings.asp">
<option value="0">Today</option>
<option value="1">1 day ago</option>
<option value="2">2 days ago</option>
<option value="3">3 days ago</option>
<option value="4">4 days ago</option>
</select>

is that right?


Reply By: crmpicco Reply Date: 1/26/2005 11:44:24 AM
think that should be:

<select name="book_date" id="book_date" onChange="location.href='display_bookings.asp'">
<option value="0">Today</option>
<option value="1">1 day ago</option>
<option value="2">2 days ago</option>
<option value="3">3 days ago</option>
<option value="4">4 days ago</option>
</select>


Reply By: joefawcett Reply Date: 1/26/2005 11:47:57 AM
That would change the location but it ignores the selected value, you might as well have a normal link.


--

Joe (Microsoft MVP - XML)
Reply By: crmpicco Reply Date: 1/26/2005 11:49:35 AM
how do i pass the value as well?

Reply By: ChrisScott Reply Date: 1/26/2005 11:54:13 AM
Place the urls in the values for the options & use something like...

onchange="location.href = this[this.selectedIndex].value;"

HTH,

Chris

Reply By: crmpicco Reply Date: 1/26/2005 11:57:24 AM
i'm not too sure what you mean, urls in the values???

<select name="book_date" id="book_date" onChange="location.href='display_bookings.asp'">
<option value="0">Today</option>
<option value="1">1 day ago</option>
<option value="2">2 days ago</option>
<option value="3">3 days ago</option>
<option value="4">4 days ago</option>
</select>

thats my drop-down, how do i pass the option or value....

Reply By: crmpicco Reply Date: 1/26/2005 11:59:01 AM
<select name="book_date" id="book_date" onChange="location.href='display_bookings.asp; this[this.selectedIndex].value'">

this doesnt work....

Reply By: ChrisScott Reply Date: 1/26/2005 12:05:29 PM
No kidding

What is the url you want to go to if "Today" is chosen (including any querystring values to tell it apart from the other options)?

Cheers,

Chris

Reply By: crmpicco Reply Date: 1/27/2005 4:11:55 AM
i wnat to go to <select name="book_date" id="book_date" onChange="location.href='display_bookings.asp'">


Reply By: crmpicco Reply Date: 1/27/2005 4:14:03 AM
the fix:

onChange="form.submit()"

Reply By: crmpicco Reply Date: 1/27/2005 7:57:42 AM
as it sits:

<select name="book_date" id="book_date" onChange="form.submit()">
<option value="<%=date()%>">Today</option>
<option value="<%=date()-1%>">1 day ago</option>
<option value="<%=date()-2%>">2 days ago</option>
<option value="<%=date()-3%>">3 days ago</option>
<option value="<%=date()-4%>">4 days ago</option>
<option value="<%=date()-5%>">5 days ago</option>
</select>

however, when i try to select 'Today' it doesnt go to the next page. only 'onChange' of the other values, 1 day ago, 2 days ago etc......

any ideas?

Reply By: joefawcett Reply Date: 1/27/2005 9:36:54 AM
Well in that case you need a default value so that you always fire the onchange:
<select name="book_date" id="book_date" onChange="form.submit()">
<option value="">Choose a date</option>
<option value="<%=date()%>">Today</option>
<option value="<%=date()-1%>">1 day ago</option>
<option value="<%=date()-2%>">2 days ago</option>
<option value="<%=date()-3%>">3 days ago</option>
<option value="<%=date()-4%>">4 days ago</option>
<option value="<%=date()-5%>">5 days ago</option>
</select>

You will then have to have an onsubmit handler on the form to check that the selectedIndex of the list is greater than 0.

Personally I think this is poor UI design, it's all too easy to choose the wrong option from a selectbox but now the form submits automatically. Better to make them pick a date and click a submit button when they can see they chose correctly.

--

Joe (Microsoft MVP - XML)
Reply By: crmpicco Reply Date: 1/27/2005 10:27:38 AM
i changed it to:

<select name="book_date" id="book_date" onChange="form.submit()">
<option selected="selected">Please Select</option>
<option value="<%=date()%>">Today</option>
<option value="<%=date()-1%>">1 Day ago</option>
<option value="<%=date()-2%>">2 Days ago</option>
<option value="<%=date()-3%>">3 Days ago</option>
<option value="<%=date()-4%>">4 Days ago</option>
<option value="<%=date()-5%>">5 Days ago</option>
<option value="<%=date()-1%>">6 Days ago</option>
<option value="<%=date()-2%>">7 Days ago</option>
<option value="<%=date()-14%>">2 Weeks ago</option>
<option value="<%=date()-21%>">3 Weeks ago</option>
<option value="<%=date()-31%>">1 Month ago</option>
<option value="<%=date()-62%>">2 Months ago</option>
<option value="<%=date()-93%>">3 Months ago</option>
<option value="<%=date()-124%>">4 Months ago</option>
<option value="<%=date()-155%>">5 Months ago</option>
<option value="<%=date()-186%>">6 Months ago</option>
</select>


Go to topic 24300

Return to index page 86
Return to index page 85
Return to index page 84
Return to index page 83
Return to index page 82
Return to index page 81
Return to index page 80
Return to index page 79
Return to index page 78
Return to index page 77