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
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
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.