Jump to content

Recommended Posts

Hello,

 

I have piece of code I have written that, when the form is submitted it sends the string from the textbox through ajax, through a database and returns a name corresponding to that string. It works fine in chrome but not in firefox and I was wondering if you could help.

If I set the function to a simple alert(code) it will fire it and work fine however when I revert it to the ajax script it simply reloads the page with the "?code=string" and ignores anything and everything in the js function.

 

This is the ajax code:

function signin(code)
{
// event.preventDefault();
var xmlhttp;
var photo;
if (code=="")
 {
 document.getElementById("resultcontents").innerHTML="lol";
 return;
 }
if (window.XMLHttpRequest)
 {// code for IE7+, Firefox, Chrome, Opera, Safari
 xmlhttp=new XMLHttpRequest();
 }
else
 {// code for IE6, IE5
 xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
 }
xmlhttp.onreadystatechange=function()
 {
 if (xmlhttp.readyState==4 && xmlhttp.status==200)
   {
var str = xmlhttp.responseText;
var split = str.split(", ");
document.getElementById("resultcontents").innerHTML=split['0'];
document.getElementById("counter").innerHTML=split['1'];
if(!(split['2'] == undefined)){
document.getElementById("webcamcanvas").innerHTML="<img src='" +split['2']+"' width='400' height='300'>"; 
}
document.getElementById("codetextbox").value="";
document.getElementById("codetextbox").focus();
   }
 }
 
xmlhttp.open("GET","files/******.php?code="+code,true);
xmlhttp.send();
}

This is the HTML form:

form onsubmit="signin(codeform.codetextbox.value)" name="codeform">
<input type="textbox" name="codetextbox" id="codetextbox" />
</form>
 
The reason it has no submit button is because firstly, it clutters up the page and secondly I'm using a barcode scanner which automatically inserts a carriage return, submitting the form.
 
Any help would be greatly appreciated!
 
Also, I'm sorry if this is in the wrong section, it's to do with both JS and Ajax and I didn't know which to choose.
 
Jacbey.
Link to comment
https://forums.phpfreaks.com/topic/279672-onsubmit-not-firing-in-firefox/
Share on other sites

Your JS code is probably triggering an error so the submit action never gets cancelled allowing the form to do it's normal submit. Check your browsers's error console for messages. You may need to go into it's settings and prevent it from clearing on navigation in order to see the error.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.