thenewprogrammer
New Member
- Messages
- 45
- Reaction score
- 0
- Points
- 0
Trying to echo out a javascript from a javascript when i press button on html page which sounds stupid but just trying to get it to work. Nothing happens and im new to this and in search of answers.
html page
clienthint.js
gethint.php
What suppose to happen is when i click the button it will say jimmy jones underneath it without refreshing where div txthint is at. Knew to this so point out how i can get this to work been stuck for while
html page
Code:
<html>
<head>
<script type="text/javascript" src="clienthint.js"></script>
</head>
<body>
<form>
First Name: <input type="button" id="txt1" value="Click Me" onclick="sub()" />
</form>
<div id="txtHint"></div><p><a href="[URL]http://www.w3schools.com[/URL]">
<img border="0" alt="Visit W3Schools!" src="b_pink.png" id="b1" /></a></p>
</body>
</html>
clienthint.js
Code:
var xmlhttp
function sub(){
xmlhttp=GetXmlHttpObject();
var url="gethint.php";
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
Code:
<?php
echo "<script type=\"text/javascript\">
document.getElementById('txtHint').innerHTML = 'jimmy jones';
</script>";
?>
What suppose to happen is when i click the button it will say jimmy jones underneath it without refreshing where div txthint is at. Knew to this so point out how i can get this to work been stuck for while