I have an onclick
event attached to a button.
Clicking the button adds a text box to the target div.
The code is:
onclick="return addBlank("param1","param2");
The function addBlank
does not have a return statement.
Clicking on the button behaves as intended in Firefox, Opera, Chrome and Safari - i.e., an empty text box is added to the target div and page is not reloaded.
Clicking on the button in IE8 forces a page reload and doesn't add anything to the target div.
Is there an onclick
inpatibility that I'm missing here?
I appreciate your taking the time to read this doubt!
I have an onclick
event attached to a button.
Clicking the button adds a text box to the target div.
The code is:
onclick="return addBlank("param1","param2");
The function addBlank
does not have a return statement.
Clicking on the button behaves as intended in Firefox, Opera, Chrome and Safari - i.e., an empty text box is added to the target div and page is not reloaded.
Clicking on the button in IE8 forces a page reload and doesn't add anything to the target div.
Is there an onclick
inpatibility that I'm missing here?
I appreciate your taking the time to read this doubt!
Why not add
return false;
to the end of the function then? It should prevent anything happening as a result of the onclick event.
IE is treating the button as a submit actor (i.e., clicking it submits the form)
The click handler needs to return false;
to prevent this.
function addBlank( p1, p2 )
{
// stuff
return false;
}