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 derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

another delete confirm q 2

Status
Not open for further replies.

mthompo

Technical User
Jul 28, 2006
98
GB
have an onclick event for my image

Code:
onclick= "if (ew_confirm('Are You Sure?')) {this.form.action='custaddcourtcars.asp';this.form.submit();this.form.a.value='D'};"

Code:
function ew_confirm(msg)
{
	var agree=confirm(msg);
	if (agree)
		return true ;
	else {
		return false ;
	}
}

can someone tell me why this submits the form even if a user clicks Cancel
when someone clicks OK i want it to submit the form
with D as the value for the form element
but if they click cancel i want it to do nothing
 
yes

Code:
<input name="Action2" type="image" id="Action2" src="images/tbot12_02.gif" width="67" height="50" border="0" onclick= "if (ew_confirm('Are You Sure?')) {this.form.action='custaddcourtcars.asp';this.form.submit();this.form.a.value='D'};">
 
that's why.

i would create a function to make it a little neater:

Code:
function doSubmit(i) {
    i.form.action = 'custaddcourtcars.asp';
    i.form.elements['a'].value = 'D';
}

Code:
onclick="if(confirm('blah')) { doSubmit(); } else { return false; }"



*cLFlaVA
----------------------------
[tt]"quote goes here"[/tt]
[URL unfurl="true"]http://www.coryarthus.com/[/url]
 
doesnt seem to change value of a
is my hidden element wrong?

Code:
<input type="hidden" name="a" value="A">
 
yep - defo inside form tags
goin home now, will check back 2mora
 
><input name="Action2" type="image" id="Action2" src="images/tbot12_02.gif" width="67" height="50" border="0" onclick= "if (ew_confirm('Are You Sure?')) {this.form.action='custaddcourtcars.asp';this.form.submit();this.form.a.value='D'};">

[1] You have to realize that input type="image" is a submit button. Hence, you don't have to script in the .submit() in the onclick.
[2] Even if you then script in the .submit() there, your line to change the input named a field is after the .submit(), the changing value is thereby not effective.

This would, I think, do.

[tt]<input name="Action2" type="image" id="Action2" src="images/tbot12_02.gif" width="67" height="50" border="0" onclick= "if (ew_confirm('Are You Sure?')) {this.form.action='custaddcourtcars.asp';this.form.a.value='D';return true} else {return false};">[/tt]
 
glad i could be so helpful as well. changing [tt]doSubmit();[/tt] to [tt]doSubmit(this);[/tt] in my example worked perfectly as well, and is slightly more portable. that's ok though.



*cLFlaVA
----------------------------
[tt]"quote goes here"[/tt]
[URL unfurl="true"]http://www.coryarthus.com/[/url]
 
am new to jscript so didnt 'spot the prob'
thanks for trying to make me learn
 
mthompo said:
yep - defo inside form tags
goin home now, will check back 2mora

As these are intelligent forums for professional people, cuold you try and avoid using "leet speak" in future? It really isn't very professional.

Dan

Coedit Limited - Delivering standards compliant, accessible web solutions

[tt]Dan's Page [blue]@[/blue] Code Couch
[/tt]
 
my apologies - was trying to get out of the office!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top