JavaScript submit(); problem in IE / Safari / FF for Mac
I'm writing a Facebook application and I want to submit a form using JavaScript. This works perfectly on Windows: Opera, Chrome, FF. But not on IE and Mac: FF, Safari.
This is the situation:
Function:
function postScore(){
document.getElementById('idscore').value = document.getElementById('countScore').innerHTML;
document.getElementById('idtime').value = document.getElementById('countTime').innerHTML;
document.forms["myScore"].submit();
}
Form:
<form action="score.php" id="myScore" method="POST">
<input type="text" name="score" id="idscore" />
<input type="text" name="time" id="idtime" />
</form>
Trigger for function:
<a href="#" onclick="postScore();">Submit</a>
Score.php does not receive any information (checked with开发者_如何学编程 print_r($_POST)) in the previously named browsers. As you can see, I made sure that the Id's and Names are different as some browsers mix these up. Any help would be highly appreciated, I'm working on this for 2 days already..
use jQuery like this
$(document).ready(function() {
$("#myscore").submit(function() {
$("#container").innerHTML = $(this).find("#idscore").val;
$("#container2").innerHTML = $(this).find("#idtime").val;
return false; // so it does not actually execute the submit
});
});
<form action="score.php" name="myScore" id="myScore" method="POST">
<input type="text" name="score" id="idscore" />
<input type="text" name="time" id="idtime" />
</form>
Try giving your form an id and then use document.getElementById('yourformid').submit();
IE's getElementById
is not case sensitive (at least in every version i checked). You should rename your form to scoreSubmitForm
or something.
Do you have any element with an id or name of "submit" anywhere on the page ? If so, try changing that to something different as it could be causing a conflict.
Also, you can try adding a name="myScore"
attribute to the form tag too.
if you want to use the id of the form just make document.getElementById("myScore").submit, or you can add a name="myScore" in the form attributs.
精彩评论