Jump to content

Div tags and ajax


ShaolinF

Recommended Posts

Hi Guys,

 

I am trying to use a div tag along with a form text box but it doesn't want to work!  :( See code below:

 

<script src="form_validation.js" type="text/javascript">

function ajaxFunction()

{var xmlHttp;

try

  {  // Firefox, Opera 8.0+, Safari  xmlHttp=new XMLHttpRequest();  }

catch (e)

  {  // Internet Explorer  try

    {    xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");    }

  catch (e)

    {    try

      {      xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");      }

    catch (e)

      {      alert("Your browser does not support AJAX!");      return false;      }    }  }

  // Function

  xmlHttp.onreadystatechange=function()

    {

    if(xmlHttp.readyState==4)

      {

  document.getElementById('ticknodiv').style.display = xmlHttp.responseText;

      }

    }

var tickno = document.signup.ticketno.value;

var queryString = "?tn=" + tickno;

  xmlHttp.open("GET","tickno.php" + queryString,true);

  xmlHttp.send(null);  }

</script>

 

        <form action="confirm.htm?id=<?php include("rand.htm"); ?>" name="signup" method="post" onsubmit="return toggleDiv(this);" id="signup">

  <label for="ticketno">How many Tickets:</label><br />

          <input type="text" onkeyup="ajaxFunction();" name="ticketno" size="1" /><span id="format_tic">x £<? echo $_SESSION['SingleTicketPrice'] = $row['TicketPrice']; }?></span><br />

          <br />

          <input type="reset" class="altButtonFormat" /> <input type="submit" value="Continue >>" class="altButtonFormat" /></p>

</form>

 

<div id="ticknodiv" style="display:none" class="red">

<ul>

<li>Too many tickets. Choose a lower amount</li>

</ul>

        </div>

 

 

 

 

tickno.php

<?php

include('db_connect.php');

$result = mysql_query('SELECT TicketsOnSale FROM event WHERE eventset = 1') or die(mysql_error());

while ($row = mysql_fetch_assoc($result)) {
}
/*
if ($_GET['tn'] > $row['TicketsOnSale'])

}*/
echo "display";

?>

Link to comment
Share on other sites

i would be suggesting you to track you code i.e

 

in code

  if(xmlHttp.readyState==4)

        {

        document.getElementById('ticknodiv').style.display = xmlHttp.responseText;

        }

do

 

alert(xmlHttp.responseText)

alert(  document.getElementById('ticknodiv'))

 

in either you are receving something wrong either in first alert your response is not proper migth be coming with some extra characters ,spaces etc or second alert might be returning you undefined.

 

kindly cross check and let us know

Regards

Link to comment
Share on other sites

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.