0

The following JavaScript works on Chrome, FF, etc. - it triggers the corresponding button - but not on IE8:

<input type="submit" value="save" name="save" class="button">

document.getElementsByName('save').item(0).click()

Is there an equivalent (native Javascript) to this which works on IE8?

1 Answers1

0

Give your form and button an id, set the button as type button, it should work on every (ancient) browser:

Javascript:

<script type="text/javascript">

function alertMsg()   {
 if (confirm("Are you sure you want to submit the form?"))  {
 //Try to submit the form
 document.getElementById('form1').submit();
 }
}
</script>

HTML

<form name="form1" id="form1" action="">
<input type="button" onclick="alertMsg()" value="Save" name="action_saveandcontinue" class="button" id="action_saveandcontinue"/>
</form>

EDIT: If you have no control over the HTML code, better read this SO question, this SO question and this MSDN documentation.

Community
  • 1
  • 1
Bud Damyanov
  • 30,171
  • 6
  • 44
  • 52
  • In this case I don't have any influence on the html code. The site is embedded in my site (same origin - so no cross-domain issue) via an iframe. Also the form has more than one input button. On top of that the html elements have no ids. – user3522374 Apr 11 '14 at 07:14