samuurai
04-03-2008, 10:50 PM
Hi,
I'm just making my first steps with Javascript, i've got a bit of PHP experience and it's helping me learn java to a small degree, but i'm having trouble doing something really simple.. Passing a variable into a script.
Here's my code
<html>
<body>
<script type="text/javascript" src="rsh/json2007.js"></script>
<script type="text/javascript" src="rsh/rsh.js"></script>
<script type="text/javascript">
window.dhtmlHistory.create();
var yourListener = function(newLocation, historyData) {
//do something;
}
window.onload = function() {
dhtmlHistory.initialize();
dhtmlHistory.addListener(yourListener);
};
</script>
<script type="text/javascript">
function ajaxFunction()
{
var xmlHttp;
try
{
// Firefox, Opera 8.0+, Safari
xmlHttp=new XMLHttpRequest();
}
catch (e)
{
// Internet Explorer
try
{
xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
}
catch (e)
{
try
{
xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
}
catch (e)
{
alert("Your browser does not support AJAX!");
return false;
}
}
}
xmlHttp.onreadystatechange=function()
{
if(xmlHttp.readyState==4)
{
document.getElementById('myDiv').innerHTML=xmlHttp.responseText;
}
}
xmlHttp.open("GET","time.php",true);
xmlHttp.send(null);
}
</script>
<button type="submit" onClick="ajaxFunction();">Click Me!</button>
<div name="myDiv" id='myDiv'>
Hello!!!
</div>
</body>
</html>
I want to pass the function ajaxFunction a variable of a url which would then populate where it says "time.php"
How can I do that?
I'm just making my first steps with Javascript, i've got a bit of PHP experience and it's helping me learn java to a small degree, but i'm having trouble doing something really simple.. Passing a variable into a script.
Here's my code
<html>
<body>
<script type="text/javascript" src="rsh/json2007.js"></script>
<script type="text/javascript" src="rsh/rsh.js"></script>
<script type="text/javascript">
window.dhtmlHistory.create();
var yourListener = function(newLocation, historyData) {
//do something;
}
window.onload = function() {
dhtmlHistory.initialize();
dhtmlHistory.addListener(yourListener);
};
</script>
<script type="text/javascript">
function ajaxFunction()
{
var xmlHttp;
try
{
// Firefox, Opera 8.0+, Safari
xmlHttp=new XMLHttpRequest();
}
catch (e)
{
// Internet Explorer
try
{
xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
}
catch (e)
{
try
{
xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
}
catch (e)
{
alert("Your browser does not support AJAX!");
return false;
}
}
}
xmlHttp.onreadystatechange=function()
{
if(xmlHttp.readyState==4)
{
document.getElementById('myDiv').innerHTML=xmlHttp.responseText;
}
}
xmlHttp.open("GET","time.php",true);
xmlHttp.send(null);
}
</script>
<button type="submit" onClick="ajaxFunction();">Click Me!</button>
<div name="myDiv" id='myDiv'>
Hello!!!
</div>
</body>
</html>
I want to pass the function ajaxFunction a variable of a url which would then populate where it says "time.php"
How can I do that?