I have an MVC3 C# .Net web app. I am firing a javaScript method of a submit button on the onclick event. It works just fine in Firefox, I see the confirm box, but not in IE 8. In IE it is always returning true and not showing the confrim box. Here is the javascript:
<script type="text/javascript">
function DoCopy() {
return confirm(($("#myField").val().contains(";" + $("#myOtherField").val() + ";")));
}
</script>
Here is the button:
<input type="submit" id="thePageSubmit" name="Command" value="Save" onclick="return DoCopy();" />
I am using jQuery but even when I use straight javaScript (document.forms[0].elements["myField"]) it works in Firefox but not IE. Any ideas?
I found the answer at this link: It's not compatible in IE
string.contains
Related
I'm using a javascript alert box. It's displaying fine in other browsers. But in Safari browser, it's displaying Cancel button instead of OK button.
How to display an OK button in javascript alert box in Safari browser?
function displayPopup(cb) {
alert('That is Great.');
}
We are calling this function here:
<input type="checkbox" id="chkmodeOnline" name="chkMode" runat="server" value="1" clientidmode="Static" onclick='displayPopup(this);' />
function complete()
{
updateUserData();
window.location = "/getans.php";
}
<input type="button" id="finish" onClick="complete();" >
Unable to redirect user to another page in IE..but it works fine in chrome and firefox
Try this JSBin http://jsbin.com/coqinunacu/1/edit?html,js
document.createElement("input").complete
complete is an input property in IE, so simply renaming click handler will help
or you may also explicitly reference window.complete
<input type="button" value="click" id="finish" onclick="window.complete()">
following Code works fine for IE, but not for Firefox (version 24.2.0 ESR)...
<input type="file" name="datei" id="data" onChange="enable();">
<input type="submit" id="submitConfig" value="Konfiguration abschicken" disabled="true" style="margin-left: 250px;">
and the triggered Script...
function enable() {
document.getElementById("submitConfig").removeAttribute("disabled");
}
is this behaviour of not reacting to EventHandlers (also tried "onClick") a "security-feature" of firefox, or is this a bug?
And is there a possible cross-browser workaround, to get the submitbutton only enabled if a file is chosen?
Jquery way works fine in all browsers. It is simple: Removing
disabled attr
$("#submitConfig").removeAttr('disabled');
Adding disabled attr
$("#submitConfig").attr('disabled','disabled');
instead of using
document.getElementById("submitConfig").removeAttribute("disabled");
use
document.getElementById("submitConfig").disabled = true;
or
document.getElementById("submitConfig").disabled = false;
I am using below line so that when i click a "New" button it will empty all the fields.
using onClick="history.go(0)" which works in IE but fails Mozilla.
<INPUT TYPE="button" onClick="history.go(0)" VALUE="New">
To empty all the fields, use reset button:
<button type="reset">New</button>
No need in JavaScript.
I have come across some strange behaviour, and I'm assuming a bug in Firefox, when removing a input submit element from the DOM from within the click event.
The following code reproduces the issue:
<form name="test_form">
<input type="submit" value="remove me" onclick="this.parentNode.removeChild(this);" />
<input type="submit" value="submit normally" />
<input type="button" value="submit via js" onclick="document.test_form.submit();" />
</form>
To reproduce:
Click "remove me"
Click "submit via js". Note that the form does not get submitted, this is the problem.
Click "submit normally". Note that the form still gets submitted normally.
It appears that, under Firefox, if you remove a submit button from within the click event it puts the form in an invalid state so that any future calls to form.submit() are simply ignored. But it is a JavaScript-specific issue as normal submit buttons within this form still function fine.
To be honest, this is such a simple example of this issue that I was expecting the internet to be awash with other people experiencing it, but so far searching has yealded nothing useful.
Has anyone else experienced this and if so, did you get to the bottom of it?
Seems to be related to the fact that you're removing the node while processing the event.
This indeed looks like a bug from Firefox.
In the meanwhile, this hack seems to work but delaying the removal:
<script type="text/javascript">
function delsubmit(el) {
window.setTimeout(function() {
el.parentNode.removeChild(el);
}, 50);
return false;
}
</script>
<input type="submit" value="remove me" onclick="return delsubmit(this)" />