Javascript disable button: FF vs IE

I have a series of buttons that create a PDF file that I want to open in a new tab. Thus, the button page remains at the top, and the PDF is open for printing. In order not to press the button twice, I will disable the button like this (I use python):

<input type='submit' value='Factureren' name='submitbutton' id='%s' onclick="javascript:document.getElementById('%s').disabled=true; document.getElementById('%s').className='button_disabled';"> % ((but_id,) *3) 

In FF3, this works fine, that is, the form is submitted, the script is executed, and then the button is disabled. In IE, the button just turns off, but the script form is not executed.

Is there a solution to this IE problem?

+3
source share
8 answers

It's easy: a disabled submit button does not submit the form in IE. Think about restructuring your code:

  • Use a regular button, disable it and call form.submit () from your handler.
  • Do not disable the button in your onclick, but save it and do it in the form of onsubmit.
+8
source

This is easier to do:

  <input type='submit' value='Factureren' name='submitbutton' id='%s' onclick="this.disabled=true; this.className='button_disabled';"> % ((but_id,) *3) 

I don’t know if this solves your problem, but this is what I would do in that case. I think you do not need "javascript:" anyway.

+5
source

You can try using a regular button and run the submit () function in the onclick event:

 <input type="button" value="Factureren" name="submitbutton" onclick="this.disabled=true; this.className='button_disabled'; this.form.submit();"> 
+3
source

Maybe try attaching a handler to the onsubmit event of the form instead of clicking a button? This will also work if the user pressed ENTER instead of pressing a button.

0
source

Instead of controlling a div, why not control the actual submit button? This works all over the place in all browsers I tested (IE6 + FF1 + and Safari)

 function toggleSubmit(){ frm=document.forms[0] if(frm.submit.disabled==true){ frm.submit.disabled=false; }else{ frm.submit.disabled=true; } } 

Then on the button is all you need to call,

 <input type='submit' value='Factureren' name='submitbutton' onclick="toggleSubmit();false;"> % ((but_id,) *3) 
0
source
 <input type="submit" value="Factureren" name="submitbutton' id="%s" onclick="this.disabled = true; this.className = 'button_disabled'; true;"> % ((but_id,) *3) 

You can use this instead of document.getElementById ('% s') . In addition, you need to return true for the onclick event.

You can also disable the button in the onsubmit handler for the form. This is probably more flawless.

In addition, it would be nice if you did not use the class specifically for the disabled button. CSS selectors are for selecting disabled buttons for you.

0
source

Take a look at this part:

 onclick="javascript:document.getElementById('%s').disabled=true; document.getElementById('%s').className='button_disabled';" 

"javascript:" is neither necessary nor incorrect.

 onclick="document.getElementById('%s').disabled=true; document.getElementById('%s').className='button_disabled';" 

"javascript:" is the URL protocol used in links, not in onclick actions.

Also, try submitting the form to submit. I think this will be correct:

 onclick="document.getElementById('%s').disabled=true; document.getElementById('%s').className='button_disabled'; this.form.submit();" 
0
source

onclick = "this.disabled = 'disabled'; this.form.submit ();" works great for me

0
source

All Articles