Jump to content

button problem


hasjem

Recommended Posts

I am busy learning ajax and i picked up a "simple" script from the internet.

if i understand this i can alter it and use it.

but it doesn't work and i do not see why. if i have a working script i can go on but as long as i do not understand why it isn't working....

who can point the mistake?

 

<script language="JavaScript" type="text/javascript">

function ajaxRequest(){

var activexmodes=["Msxml2.XMLHTTP", "Microsoft.XMLHTTP"] //activeX versions to check for in IE

if (window.ActiveXObject){ //Test for support for ActiveXObject in IE first (as XMLHttpRequest in IE7 is broken)

  for (var i=0; i<activexmodes.length; i++){

  try{

    return new ActiveXObject(activexmodes)

  }

  catch(e){

    //suppress error

  }

  }

}

else if (window.XMLHttpRequest) // if Mozilla, Safari etc

  return new XMLHttpRequest()

else

  return false

}

</script>

<script language="JavaScript" type="text/javascript">

var mygetrequest=new ajaxRequest()

mygetrequest.onreadystatechange=function(){

if (mygetrequest.readyState==4){

  if (mygetrequest.status==200 || window.location.href.indexOf("http")==-1){

  document.getElementById("result").innerHTML=mygetrequest.responseText

  }

  else{

  alert("An error has occured making the request")

  }

}

}

var namevalue=encodeURIComponent(document.getElementById("name").value)

var agevalue=encodeURIComponent(document.getElementById("age").value)

mygetrequest.open("GET", "basicform.php?name="+namevalue+"&age="+agevalue, true)

mygetrequest.send(null)

</script>

 

 

<form method="get" action="">

Your name: <input type="text" id="name" name="name" size="25" /> <br />

Your age: <input type="text" id="age" name="age" size="25" /> <br />

<input type="button" value="submit" onClick="ajaxget()" />

</form>

 

<div id="result"> </div>

 

and as basicform.php:

 

<?

$name=htmlspecialchars($_GET['name']);

$name=stripslashes($name);

$age=(int)$_GET['age'];

echo "<span style='color:red'>Welcome <b>$name</b> to JavaScript Kit. So you're <b>$age</b> years old eh?</span>";

?>

Link to comment
https://forums.phpfreaks.com/topic/201156-button-problem/
Share on other sites

Please post code in the code tags. It makes it much easier to read.

 

So what problem are you having, other than "it isn't working?" The more details, the better.

 

At first glance, it appears that your button is calling a function called "ajaxget()," but there is no such function.

Link to comment
https://forums.phpfreaks.com/topic/201156-button-problem/#findComment-1055468
Share on other sites

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.