Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to tell which button causes form to submit?

Status
Not open for further replies.

quinnipiac0807

Programmer
Oct 25, 2004
38
US
I have a form that has two asp:buttons on it. When one button is pushed, I want the page to do some validation that I'me doing with Javascript and submit based on a condition, BUT, if the second button is pushed, I just want it to submit without any validation. What I'm doing now is, in the form tag onsubmit="javascript:return Submit()".

function Submit(){
var index = document.all.ddlAppRoles.selectedIndex;
var roleid = document.all.ddlAppRoles.options[index].value;
var userid = document.all.userSelect1_txtid.value;
var username = document.all.userSelect1_txt.value;
var valid = document.all.userSelect1_spnValid.innerText;

if(roleid > 0 && userid != '' && username != '' && valid != 'Invalid'){
return true;
}
else{
alert('Please enter all information');
return false;
}

I know that the validation part works, but if it's a certain button that I'm pressing I just want to submit the form, b/c it doesn't matter what's in those variables. Any suggestion?
 
Change the second button to add an onclick. That onclick can set the form onsubmit to be empty... and then the form is submitted without validation. Here is an example of what I mean:

Code:
<input type="submit" name="second_button" value="Second Button"
onclick="this.form.onsubmit = '';"/>

Cheers,
Jeff

[tt]Jeff's Page [/tt][tt]@[/tt][tt] Code Couch
[/tt]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top