<form action="http://google.com">
<input type="submit" onclick="javascript:this.disabled='disabled';return true">
</form>
It works in Firefox, but not in IE8, Safari (It should forward me to Google's site, it but doesn't happen.). Why?
Try this instead:
<input type="submit" onclick="this.disabled='disabled';form.submit()">
Edit: Added form. as per wamp's comment.
You don't need the javascript: pseudoprotocol. This should work:
onclick="this.disabled=true"
and you don't need to return true, that'll happen automatically.
Related
Please tell me how to make it work in older browsers as html5 not understand everything, but inside the form can not be put input:
<form onsubmit="checkd();return false" id="form2">
...
</form>
<input type="submit" value="Submit" form="form2" />
P.S. I do not know JS, be grateful for a detailed explanation or example ^^
With JQuery you may do something like:
$("form2").on("submit", function(){
...
});
I have a huge and annoying problem.
I'm using jQuery (version 1.7.1, it's not an option to update jQuery or the browser).
I added some Javascript to handle <ctrl>+s as a submit, instead of a save.
It works perfectly well in every browser, except Opera.
In Opera, it submits, but to a new page.
If anyone has found a way to fix this, can you please provide some help? I would appreciate a lot!
This is quite an annoying bug and I use that feature a lot in the backoffices I'm developing.
Here is an example of the Javascript code used:
$(window).keydown(function(e){
if(e.ctrlKey&&e.keyCode==83)
{
e.preventDefault();//disable page saving
var a=$(':focus');//gets the focused element
if(!a.length){a=$('form:eq(0)');}else{a=a.parents('form');}//if no element is focused, gets the 1st form
a.find("input[type=button].submit, button[type=submit], input[type=submit], form a.submit").click();//triggers the click in the button
if(a.find('input[type=submit]'))a.submit();//'silly' line added as a desperate attempt, ignore it
}
});
The HTML code is a simple form like this:
<form action="#" method="POST" [target="_self"]>
<input type="text" name="fld">
<input type="submit" name="sub" value="Submit">
</form>
Using a <button type="submit"> submits to the same page AND to a new tab.
I found a solution!
This is a really UGLY hack.
This is the new Javascript:
$(window).keydown(function(e){
if(e.ctrlKey&&e.keyCode==83)
{
e.preventDefault();
var a=$(':focus');
if(!a.length){a=$('form:eq(0)');}else{a=a.parents('form');}
a.find("input[type=button].submit, form a.submit").click();
if(window.opera&&a.find('input[type=submit],button[type=submit]').length)a.submit();
else a.find("input[type=submit],button[type=submit]").click();
}
});
And the HTML must change to this:
<form action="#" method="POST" [target="_self"]>
<input type="text" name="fld">
<input type="hidden" name="sub" value="1"><!-- to validate if the form was submitted on opera -->
<input type="submit" name="sub" value="Submit">
</form>
Since the form submission works perfectly on the other browsers, we can leave the default behavior for them, changing only the way that Opera works.
As I said: it's an UGLY hack, but works.
Thank you #Bergi for your idea. I just had to adapt it.
This is the form
<form action="post" name="default_form">
<input type="hidden" value="d" name="def" />
<div id="load_result"></div>
</form>
But the following code doesn't works in IE but properly works in mozilla,opera
var body = document.forms.default_form.serialize();
Any idea?
The form element does not have a serialize() method.
It isn't in the HTML5 spec either.
If you are talking about jQuery's serialize(), then you need to wrap the matched set with the jQuery object $(document.forms.default_form) or even $('form[name="default_form"]').
Today i StumbleUpon a strange cache behavior of Firefox 4 which is described bellow.
There is a form <form name="widget">
<input type="hidden" name="position" value="-1" />
</form>
On an arbitrary event i have changed it to say "rss".
After refreshing the page using "F5", i access the value of alert(document.widget.position.value); which is returning "rss". WHY THE OLD VALUE?
But after refreshing the page using "Control+F5", i access the value of alert(document.widget.position.value); which is returning correct "-1". WHY NOT FIRST TIME?
I am really confused by this behavior.
NOTE: Only FireFox4 is doing it, chrome i fine but did not tested on ie.
I think it's FF's caching of forms/input element values that's bugging you. You may want to use:
<form id="widget">
<input type="hidden" id="position" value="-1" />
</form>
and to change the value:
document.getElementById('position').value = /*[your value]*/;
Furthermore <form ... autocomplete="off"> seems to work.
I have simple form.
<form target="_blank" action="somescript.php" method="Post" id="simpleForm">
<input type="hidden" name="url" value="http://...">
<input type="hidden" name="code" value="wrxosf">
</form>
...and there are some anchor link
Do it!
It works fine in FireFox or IE, but Google Chrome.
Chrome does once, then link become unclickable.
Also had such problem.
The decision was to add something random to URL each time before submitting.
HTML:
<form action="go.php" method="post" target="_blank" id="go">
...
</form>
JavaScript (jQuery):
$('#go').attr('action','go.php?'+Math.random()*1000).submit();
Forms with target="_blank" submiting only once.
This is webkit & chromium bugs.
I am running Chrome 7.0.5 and also still having this problem. Setting the action to something different each time as suggested above works! :)
This problem was fixed in the latest version of Chrome 5.0.375.55