Forum Moderators: open

Message Too Old, No Replies

Combining Two onClick JavaScript Actions

Newbie question

         

boxfan

4:17 pm on Sep 8, 2006 (gmt 0)

10+ Year Member



Hi I am trying to combine the following into one function which can be fired off from a submit button in a form.

onclick="javascript:return confirm('Did you change the Shipping Status? \nClick Cancel to go back')"

onclick="this.disabled=true;"

I need the user to confirm that they changed the shipping status first and then if true then I need the submit button disabled. If they click cancel from the prompt then I need the submit button to remain enabled.

I tried calling the two like this

onClick="javascript:return confirm('Did you change the Shipping Status? \nClick Cancel to go back'); this.disabled=true;"

But when the user clicks OK the submit button is not disabled.

I think I need the two rewritten into a function and then just call the function from the submit button.

Any help please?

alanderson

6:16 pm on Sep 8, 2006 (gmt 0)

10+ Year Member



Rewritting them into a function is the way that I would do it.

but it could be done as a oneliner;

javascript:if(confirm('Confirmation Question')){this.disabled=true}else{this.disabled=false}

I have not tested this but it probably could be shortened more to

javascript:this.disabled=(confirm('Question'))?true:false;

boxfan

7:08 pm on Sep 8, 2006 (gmt 0)

10+ Year Member



Thank you very much for that.

The first code works except if you click cancel the action is still completed (Order is printed).

If the user clicks cancel then the form should not be processed.

Any ideas?

Here is the entire form code

<form action="/" method="get" name="printform" id="printform" target="_blank">
<input type="hidden" name="M_OrderID" value="<?php echo $M_OrderID;?>" />
<input type="Submit" name="Submit" id="Submit" value="Print Order" onclick="javascript:if(confirm('Did you change the Shipping Status? \nClick Cancel to go back')){this.disabled=true}else{this.disabled=false}" onfocus="blur()" /></form>

[edited by: boxfan at 7:12 pm (utc) on Sep. 8, 2006]

alanderson

7:11 pm on Sep 8, 2006 (gmt 0)

10+ Year Member



sure just change it to this;

javascript:if(confirm('Confirmation Question')){this.disabled=true}else{return false}

boxfan

7:13 pm on Sep 8, 2006 (gmt 0)

10+ Year Member



BEAUTIFUL!

Thank you.