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
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>
";
?>

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.