do not want page to reload if selected index of control is 0

G

Guest

Hi I have a page that pops up a warning box if a selection is not made, see
below.
<script language="javascript" event="onclick" for="btn_submit">
if(document.Form1.drp_dn_arriv.selectedIndex==0)
window.alert("Missing Arrival Time");
Anyhow the btn_submit will post back to the server and reload the page.
Just wondering if anyone knows how to prevent this if the
drp_dn_arriv.selected index = 0? This is a dropdown box and when the index
is 0 it means a selection has not been made. Thanks.
 
P

Peter Rilling

Try returning "false" from your handler when you want postback to be
canceled.
 
G

Guest

Hi thanks for the information, just wondering is this done in Java script,
and what would it look like?
--
Paul G
Software engineer.


Peter Rilling said:
Try returning "false" from your handler when you want postback to be
canceled.
 
P

Peter Rilling

Yes, in JavaScript.

<script language="javascript" event="onclick" for="btn_submit">
if(document.Form1.drp_dn_arriv.selectedIndex==0)
{
window.alert("Missing Arrival Time");
---> return false; <---
}
</script>

I have not done this within a handler defined in a script block, usually
just from a function or something, but this might work for you.

Paul said:
Hi thanks for the information, just wondering is this done in Java script,
and what would it look like?
 
G

Guest

Hi thanks for the additional information. It works!
I have 4 controls that must have valid entries before the postback takes
place,
also have a popup window for each on missing.
</script>
<script language="javascript" event="onclick" for="btn_submit">
if(document.Form1.drp_dn_arriv.selectedIndex==0)
window.alert("Missing Arrival Time");
if(document.Form1.drp_dn_dtype.selectedIndex==0)
window.alert("Missing Data Type");
if(document.Form1.lstbx_dest.selectedIndex==0)
window.alert("Missing Destination");
if(document.Form1.dr_lst_event.selectedIndex==0)
window.alert("Missing Event");
if ((document.Form1.drp_dn_arriv.selectedIndex!=0) &&
(document.Form1.drp_dn_dtype.selectedIndex!=0) &&
(document.Form1.lstbx_dest.selectedIndex!=0) &&
(document.Form1.dr_lst_event.selectedIndex!=0))
{
return true;
}
else
{
return false;
}
</script>
 

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,743
Messages
2,569,478
Members
44,898
Latest member
BlairH7607

Latest Threads

Top