Hi all

i have this problem with my ajax script that it is working with IE but not on firefox.this script is updating database. following is AJAX Script::

<script type="text/javascript">
 function ajaxpost(){ 
var mypostrequest;
  // Firefox, Opera 8.0+, Safari
  mypostrequest = new XMLHttpRequest();
catch (e)
  // Internet Explorer
   mypostrequest = new ActiveXObject("Msxml2.XMLHTTP");
  catch (e)
    mypostrequest = new ActiveXObject("Microsoft.XMLHTTP");
  if (mypostrequest.readyState == 4) { 
    res = mypostrequest.responseText;  // These following lines get the response and update the page
   document.getElementById('result').innerHTML = res;
	//document.getElementById('result').value = res;

var parameters =  
var url = "https://client.extremescreamproductions.com/leads/ajaxpost.php";
mypostrequest.open("POST", url, true);
mypostrequest.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
mypostrequest.setRequestHeader("Content-length", parameters.length);
mypostrequest.setRequestHeader("Connection", "close");

HTML page is::

<form  method = "post"action="" id="action_time">  
  <tr><td>Client</td><td><input name="client" type="text" id="client" value="<% print $hname; %>"/> </td>
        <td>User</td><td><input name="user" type="text" id="user" 
		value="<% print $auth->auth[first_name]." ".$auth->auth[last_name]; %>"/> </td></tr>
   <tr><td>From</td><td><input name="frmtim" type="text" id="frmtim" maxlength="8" value="<?php echo $cur_time;?>"/></td>
        <td>To</td><td><input name="totim" type="text" id="totim" maxlength="8"/></td></tr>
    <tr><td>Title</td><td><input name="title" type="text" id="title"/> </td>
         <td>Type</td><td><select name="type"><option id="opt1" value="type1">Type 1</option>
                 <option id="opt2" value="type2">Type 2</option>
                 <option id="opt3" value="type3">Type 3</option> 
                 <option id="opt4" value="type4">Type 4</option>
 </select> </td><td></td><td></td></tr>
    <tr><td>Description</td><td colspan="3"><textarea name="desc" id="desc" rows="5" cols="15">description goes here</textarea> </td></tr>
       <tr><td>Date</td><td><input name="date" id="date" size="15" value="<?php echo $cur_date;?>"></td>     <td colspan="2">
	   <input type="submit" value="Submit" name ="post_time" id="actiontime" class="buttons" onClick="ajaxpost(); return false;"/></td></tr>

PHP Script (ajaxpost.php)::

$client = $_POST['client'];     
$user = $_POST['user'];      
$frmtim = $_POST['frmtim']; 
$totim = $_POST['totim'];
$title = $_POST['title'];      
$type = $_POST['type'];      
$desc = $_POST['desc']; 
$date = $_POST['date'];     
$databasehost = "localhost";
    $databasename = "db";  
    $databaseusername ="user";
    $databasepassword = "pass";
    $con = @mysql_connect($databasehost,$databaseusername,$databasepassword) or die(mysql_error());
            @mysql_select_db($databasename) or die(mysql_error());
if($h1 > $h2){
        $second1=$s1+($h1*3600)+($m1*60);//converting it into seconds
		$second2=$s1+($h1*3600)+($m1*60);//converting it into seconds
if ($second1==$second2)
if ($second1<$second2) //
            $second1=$second1+(24*60*60);//adding 24 hours to it.
        //print $second3;
        if ($second3==0)
            $h3=floor($second3/3600);//find total hours
$remSecond=$second3-($h3*3600);//get remaining seconds
        if ($remSecond==0)
            $m3=floor($remSecond/60);// for finding remaining  minutes
        if($h3==0)//formating result.
        $totaltime = 0; 
		$th = 0;
		$tm = 0;
		$ts = 0;  
        $total_tim = "$h3:$m3:$s3";
		$pkstr  = $frmtim;
		$pkstr .= $date;
		$pkstr .= $user;
        $pk = md5("$pkstr");
        $insert_query="insert into actiontime values('$pk','$client','$user','$total_tim','$title','$type','$desc','$date');";
        $sel_query = "select total_time from actiontime where client ='$client' AND user = '$user';";
        $result = @mysql_query($sel_query,$con);  
		  while($values =  mysql_fetch_array($result)){ 
         $a = $values['total_time'];
		 $th = $th + $h;
		 $tm = $tm + $m;
		 $ts = $ts + $s;
			$th=floor($second/3600);//find total hours
			$remSecond=$second-($th*3600);//get remaining seconds
			$tm=floor($remSecond/60);// for finding remaining  minutes
			$totaltime = "Hr:$th Min:$tm Sec:$ts";	
		 echo $totaltime;

i get no error on firefox.
i have tried it on firefox 2.0 and 3.0 as well.Please help

Thanks a million in advance
jyoti u

Recommended Answers

All 2 Replies


I see two problems.

First, the <select> box is missing the ID attribute.
IE incorrectly uses the name attribute when an ID tag is missing, which explains why this works in IE.

Also, the <input type="submit"> button should not be used to trigger scripts like that. Unlike the onsubmit event of the <form> element, if the <input> onclick event returns false, as it does in your script, the form could still be submitted.
(IE and Firefox apparently do stop it tho.)

To fix that, try changing the <input type="submit"> to <input type="button"> . That should just trigger the script.

Thanks a lot !!!!
It worked....you r an angel to me.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, learning, and sharing knowledge.