Window.location not working in Internet explorer - javascript

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()">

Related

setTimeout function not working on firefox

I am trying to use
<input type="submit" name="add" class="buy" onClick="setTimeout('history.go(0);',2000);"/>
It reloads the page on click after two seconds in chrome but it doesnt work in Firefox.
I went through this Why does window.location.reload need setTimeout to work in firefox. It still didn't work for me. Please help me find a way I can achieve my required functionality accross both browsers.
This is how I made it work.
<input type="submit" name="add" class="buy" onClick="timeDelay()"/>
<script>
function timeDelay(){
setTimeout(function(){
window.location.reload(true);
},6000);
}
</script>

no reaction to Eventhandler by input type=file in Firefox?

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;

onClick="history.go(0)" doesn't works in mozilla but works in IE. How to resolve this issue in mozilla browser

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.

Clearing file input box in Internet Explorer

I have an file upload box and a clear button on my page. When I press the clear button, I want the text in the file upload box to be cleared.
The following works in Firefox, but doesn't in IE (the text stays there). Is there a workaround for this?
$("#clear").click( function() {
$("#attachment").val("");
//document.myform.attachment.value = "";
})
HTML:
<form name="myform">
<input type="file" name="attachment" id="attachment" />
</form>
<br /><button id="clear">Clear Attachment</button>
jsFiddle
One solution I've found is simply doing:
document.getElementById('myUploadField').parentNode.innerHTML = document.getElementById('myUploadField').parentNode.innerHTML;
Seems like it shouldn't work, but it does.
This solution is more elegant than cloning the input element. You wrap a <form> around the element, call reset on the form, then remove the form using unwrap(). Unlike the clone() solutions above, you end up with the same element at the end (including custom properties that were set on it).
Tested and working in Opera, Firefox, Safari, Chrome and IE6+. Also works on other types of form elements, with the exception of type="hidden".
http://jsfiddle.net/rPaZQ/
function reset(e) {
e.wrap('<form>').closest('form').get(0).reset();
e.unwrap();
}​
It's readonly in IE8 onwards, so you can't clear it. The simplest way around this security feature is to replace the element with a copy.
Edit Found a previous answer to this that suggests the same approach! Clearing <input type='file' /> using jQuery
This worked for me:
$("input[type='file']").replaceWith($("input[type='file']").clone(true));
use simple javascript:
formname.reset();
See the Demo: http://jsfiddle.net/rathoreahsan/YEeGR/
Try to use the below method to clear the input file.
Include this script:
<script>
function clearFileInputField(tagId) {
document.getElementById(tagId).innerHTML =
document.getElementById(tagId).innerHTML;
}
</script>
Change HTML to this:
<div id="uploadFile_div">
<input type="file" class="fieldMoz" id="uploadFile" onkeydown="return false;" size="40" name="uploadFile"/>
</div>
<a onclick="clearFileInputField('uploadFile_div')" href="javascript:noAction();">Clear</a>`
Use the old-fashioned <input type="reset" value="clear this">

JavaScript removeChild(this) from input[type="submit"] onclick breaks future use of form.submit() under Firefox

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)" />

Categories