Jump to content

[SOLVED] Lookin for easy ajax help


thenewperson

Recommended Posts

Trying to have words come out from php file but extremely knew to this and havnt a clue. Just trying to echo out javascript in field txtHint from the php file after the button is clicked

 

html page

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

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

<div id="txtHint"></div><p><a href="http://www.w3schools.com">
<img border="0" alt="Visit W3Schools!" src="b_pink.png" id="b1" /></a></p>

</body>
</html>

 

clienthint.js

var xmlhttp

function sub(){



xmlhttp=GetXmlHttpObject();

var url="gethint.php";
url=url+"?q=";
url=url+"&sid="+Math.random();
xmlhttp.open("GET",url,true);
xmlhttp.send(null);

}

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
echo "<script type=\"text/javascript\">
function changeText(){
document.getElementById('txtHint').innerHTML = 'jimmy jones';
}
</script>
";
?>

Link to comment
https://forums.phpfreaks.com/topic/179902-solved-lookin-for-easy-ajax-help/
Share on other sites

I might be overlooking something but by simply looking at your code it looks like you created the function but never called it. Try this:

 

<?php
echo "<script type=\"text/javascript\">
function changeText(){
   document.getElementById('txtHint').innerHTML = 'jimmy jones';
}
changeText();
</script>
";
?>

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.