php - Ajax form sending request on page load -


i new ajax , having think small problem. wondering if 1 able me?

the problem:

in index.php file within head tag have following:

<script type="text/javascript">    var time_variable;    function getxmlobject()  //xml object  {     var xmlhttp = false;     try {       xmlhttp = new activexobject("msxml2.xmlhttp")  // old microsoft browsers     }     catch (e) {       try {         xmlhttp = new activexobject("microsoft.xmlhttp")  // microsoft ie 6.0+       }       catch (e2) {         xmlhttp = false   // no browser accepts xmlhttp object false       }     }     if (!xmlhttp && typeof xmlhttprequest != 'undefined') {       xmlhttp = new xmlhttprequest();        //for mozilla, opera browsers     }     return xmlhttp;  // mandatory statement returning ajax object created  }    var xmlhttp = new getxmlobject();   //xmlhttp holds ajax object  function ajaxfunction() {    var getdate = new date();  //used prevent caching during ajax call    if(xmlhttp) {       var name = document.getelementbyid("name");      var date1 = document.getelementbyid("date1");      var date2 = document.getelementbyid("date2");       xmlhttp.open("post","http://heathrowsafeparking.co.uk/modules/mod_hspbooking/calc_days.php",true); //calling testing.php using post method      xmlhttp.onreadystatechange  = handleserverresponse;      xmlhttp.setrequestheader('content-type', 'application/x-www-form-urlencoded');      xmlhttp.send("name=" + name.value + "&date1=" + date1.value + "&date2=" + date2.value);      }  }    function handleserverresponse() {     if (xmlhttp.readystate == 4) {       if(xmlhttp.status == 200) {         document.getelementbyid("message").innerhtml=xmlhttp.responsetext; //update html form element        }       else {          alert("error during ajax call. please try again");        }     }  }  </script> 

in body have following; submit button calls function onclick:

<form id="hspcalc">  <table width="162" border="0" align="center" cellpadding="2" cellspacing="2" id="quoter" style="width:162px; margin:auto; font-family:verdana; font-size: 12px; background-color:#293a4b; color:#fff;"  >    <tr>    <td  height="" align="center" valign="top" style="padding-left:;">      <p style="margin-top:;">      <img src="http://heathrowsafeparking.co.uk/images/stories/getquote_but.png" border="0"  /><br />      <div id="message" name="message"></div>       name:<br />        <input name="name" type="text" class="rounded" id="name" />        <br />        <br />    date of departure:<br />        <input name="date1" type="text" class="rounded" id="date1" onfocus="showcalendar('',this,this,'','holder1',0,30,1)" value="" />        <br />        <br />        date of arrival (return):<br />        <input name="date2" type="text" class="rounded" id="date2" onfocus="showcalendar('',this,this,'','holder2',0,30,1)" value="" />            <br />          <input type="button" value="submit" onclick="ajaxfunction();" />      </p>      </td>  </tr>  </table>  </form> 

this works well, however, when call index.php file via inclusion, eg:

<?php include("modules/mod_hspbooking/index.php"); ?> 

... find seems page submitting (calling function) onload, instead of waiting user click submit button.

i cant seem find solution , appreciate if lend hand having quick , providing recommendations. please visit url problem in action (right hand side reading "unfortunately, are...").this should display form, waiting user input , click of submit button.

http://heathrowsafeparking.co.uk

to see form running stand alone , working (i.e. without calling via include) please visit here:

http://heathrowsafeparking.co.uk/modules/mod_hspbooking/index.php

for reference closing line of "calc_days.php" file echos message user displayed in div called "message":

thanks in advance , support.

regards

tom

this doesn't appear ajax issue, no request occurs after loading page first link, assumption automatically submitting mistake. should review php code check how module determines whether form has been submitted, appears following code path when embedded.

you should tag question php.

update: having seen more of code, problem turned out configuration of joomla module, , indeed server side.


Comments

Popular posts from this blog

apache - Add omitted ? to URLs -

redirect - bbPress Forum - rewrite to wwww.mysite prohibits login -

php - How can I stop spam on my custom forum/blog? -