Javascript with Submit Button

J

James

I have an ASP button on my form that will e-mail several people, and I'd
like to disable it once the user clicks on it, so that they can only click
on it once.

I have a client side javascript confirmation box that says 'Are you
sure...?' and when a user clicks OK, it seems like I have two options. I
can either disable the box, or have the submit work. When I disable it, it
doesn't post. I'm returning true/false based on what they click in the
confirm box like this:

document.getElementById('pbSend').disabled = true;

if (confirm('Are you sure you want to send this?') == true)
{
return true;
}
else
{
document.getElementById('pbSend').disabled = false;
return false;
}

Any thoughts?
 
B

Bruce Barker

you need to disable it after the submit. either add the disable to the
onsubmit routine or use a timer:


if (!confirm('Are you sure you want to send this?'))
return false;
else
{
window.setTimeout("document.getElementById('pbSend').disabled =
false",1);
return true;
}

-- bruce (sqlwork.com)
 
J

Jay Douglas

Your example may have issues with client side valiation. Try running the
post back event reference then disable the button. An example is:

private void btnSendMassEmail_PreRender(object sender, System.EventArgs e)
{
Button btn = (Button) sender;
btn.Attributes.Add("onclick",
string.Format("{0};this.disabled=true;",
GetPostBackEventReference(btn)));

}
 

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

Top