Jump to content

help with simple ajax


thenewperson

Recommended Posts

Trying to make image roll over using ajax just for test. Extremely new to this so be easy on me.

Dont want the image roll over effect till i click submit if thats possible. But the rollover doenst work after pressing submit.

 

html page

<html>
<head>
<script type="text/javascript" src="clienthint.js"></script>
</head>
<body>

<form>
First Name: <input type="submit" id="txt1" onsubmit="sub()" />
</form>

<span id="txtHint"><p><a href="http://www.w3schools.com" target="_blank">
<img border="0" alt="Visit W3Schools!" src="b_pink.png" id="b1"
onmouseover="mouseOver()" onmouseout="mouseOut()" /></a></span></p>

</body>


</html>

 

 

 

clienthint.js page

 

 

var xmlhttp

function sub(){
var url="gethint.php";
url=url+"?q="+str;
}

function stateChanged()
{
if (xmlhttp.readyState==4)
  {
  document.getElementById("txtHint").innerHTML=xmlhttp.responseText;
  }

  
function GetXmlHttpObject()
{
if (window.XMLHttpRequest)
  {
  // code for IE7+, Firefox, Chrome, Opera, Safari
  return new XMLHttpRequest();
  }
if (window.ActiveXObject)
  {
  // code for IE6, IE5
  return new ActiveXObject("Microsoft.XMLHTTP");
  }
return null;
}

 

gethint.php

<?php

$q=$_GET["q"];

echo "<script type=\"text/javascript\">
function mouseOver()
{
document.getElementById(\"b1\").src =\"b_blue.gif\";
}
function mouseOut()
{
document.getElementById(\"b1\").src =\"b_pink.gif\";
}
</script>";
?>

Link to comment
https://forums.phpfreaks.com/topic/179881-help-with-simple-ajax/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.