Jump to content

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

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.