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()">
I know there is a lot of questions here with the same problem. I have tried A LOT of solutions but none has worked for me. I got a back button but it clears the form content in IE8 (not in other browsers) and I need it to work in IE8. When I started with my code I used:
<input type="button" value="Back" onclick="history.back(-1)" />
And it worked, for a while! But suddenly it stopped working and clears the form content for me. I don't know why..
I have tried:
http://www.w3schools.com/jsref/met_his_back.asp
<a id="backButton" title="Back" href="javascript:history.go(-1)" return true;">Back</a>
<a id="backButton" title="Back" href="javascript:history.go(-1)" return false;">Back</a>
<input type="button" value="Back" onclick="window.history.back()" />
<button onclick="history.back()">Back</button>
The button is working but i clears the form JUST in IE..
UPDATE
I tried with a new dokument with one if/else-statement and it's working. But when I use nestred if/else-statements it won't work. IE8 clears the form.
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 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">
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)" />