Form submit with javascript works in Google Chrome only once - javascript

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

Related

Submiting a form from javascript (using jQuery) opens in new tab in Opera 12.16

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.

Chrome doesn't remember input field value

I'm using HTML code like this:
<form method="post" action="#">
<input type="text" name="inputFIeld" id="someVal" value="" />
<button id="submitFun" type="submit">Dodaj</button>
</form>
The only thing I do is preventDefault on submit button click and then I make an ajax call to the server.
It works just fine on all browsers except chrome. Autocomplete on chrome just doesn't work.
I find a link on chrome site :
Chrome : You should have to activate autocomplete :
https://support.google.com/chrome/answer/142893?hl=en

document.getElementByID Not Working in IE 8

I have never done this before so I apologize if I don't describe my issue good enough or don't use all the right syntax.
What I have on my website is an email form. The user can type in a message, along with their name and some other data. Once they finish filling out the form they can submit it and it goes to my email and all is well. Because the form has JavaScript in it, I automatically had it hidden with CSS and then made it visible through JavaScript. That way if the user has their JavaScript turned off the form won't appear.
And it works great. And I thought it displayed great too. I checked it across all my local testing browsers (Chrome 21, FF 14, IE 9, Opera 12 and Safari 5) as well as through Adobe Browser lab for IE 8, 7 and 6. In all of them it looked fantastic. I even checked it on my Android phone and my girlfriend's Blackberry. It looked fine.
Until I tested it on my mom's computer with IE 8. Although in Adobe Browserlab it says the form displays, in a real test the form doesn't show up.
You can test it for yourself here.
The issue is with the form id, "emailForm". My Form has the markup like so:
<form id="emailForm" method="POST" action="../javascript/email_form.php" onSubmit="return validateForm();">
<label id="emailSubjectLabel">Email Subject*:</label><input class="form" title="Email Subject" type="text" name="subject" id="emailSubject"><br>
<label id="nameLabel">Your Name*:</label><input class="form" title="Your Name" type="text" name="name" id="yourName"><br>
<label id="emailLabel">Your Email:</label><input class="form" title="Your Email Address" type="text" name="email" id="yourEmail"><br>
<label id="messageLabel">Your Message*:</label>
<textarea class="form" title="Write Something..." name="message" id="message" cols="40" rows="5"></textarea>
<input class="button" type="submit" value="Submit">
<p class="error">* required.</p>
</form>
My CSS has a whole bunch of code, but it has this in regards to making the form invisible:
#emailForm, #javaText {
display: none;
}
(note: #javaText is some text on the screen that also is hidden unless the user has JavaScript installed. It also doesn't work in IE 8. Just for simplicity I'm not mentioning it.)
And the JavaScript looks like this:
document.getElementById("emailForm").style.display = "block";
document.getElementById("javaText").style.display = "inline";
function validateForm() {
//function that validates the form
}
I've placed the JavaScript at the bottom of the page, hoping it would help. I've tried changing the style of the content right on the main HTML page, I've checked my mother's JavaScript and it is enabled. I just don't know why it isn't working.
If somebody could tell me what I'm doing wrong, I'd be very thankful. This has been giving me a headache for a week now.
(And yes, I've told her IE sucks and she should go with Chrome, but the reason she doesn't is a whole different story...)
Thanks for your help. I can't wait to hear what the solution is!
IE8 is not loading your form_validation.js file and that's why it isn't running your initialization code in that file.
You need to change the type on your script tag to type="text/javascript" or remove the type entirely. You have type="application/javascript" which is not correct.
After further exploration, see Why doesn't IE8 recognize type="application/javascript" in a script tag? for more discussion.

AOL 9.0 IE7 javascript Submit problem

I'm having some problems with AOL and IE 7.
Some members on my site have this setup and I'm having trouble getting some forms to work for them.
The html/javascript is this
<li >Award</li>
<form action="" name="form_user_award_give" method="post">
<input type="hidden" name="action" value="Give Award"/>
</form>
function photo_user_award_give() {
//simple function to submit a form
document.form_user_award_give.submit();
}
I've just taken the main bits just to give you a flavour.
I also have another problem with another button.
here is the code.
<li>
<form action="#edit_box" id="edit_photo_form" method="post">
<a onclick="document.getElementById('edit_photo_form').submit();" style="background-image:url('http://www.ephotozine.com/v5/images/site/pencil.png');" href="javascript:void(0)">Edit</a>
<input type="hidden" name="action" value="Edit"/>
</form>
</li>
I need to keep the elements as they for style are which is why I haven't used a submit button.
Does anyone have any ideas?
Or a place to download AOL 9.0?
Thanks
Richard
Got the answer instead of href="javascript:;" or href="javascipt:void;" use href="#" as the page is refreshing anyway this seems to do the trick. or event #nogo to keep the screen where it is

Why doesn't this JavaScript work in IE8?

<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.

Categories

Resources