Jump to content

modify w3schools php ajax database code


bbunlock

Recommended Posts

I have come accross a script suplied at w3schools (http://www.w3schools.com/PHP/php_ajax_database.asp) however I would like your help in modifying it to serve my purpose, below are the modifications I would like help with.

 

1, I would like to use standard links instead of a drop down form, so when a link is clicked it shows the results.

 

2, instead of sending just one paramater to the javascript code (value="?") I would like to send 2 paramaters in the link ("uid" and "up_type")

 

3, I would like it to display the first link details when page loads (so dont have to click a link to activate it on loadup) so by default the first link would be loaded on page load.

 

If this was a standard link it would be somthing like the following "usrup.php?uid=some_id&up_type=some_type" its the "uid" and "up_type" that I need sent to the javascript code, the form only allows value="?" I need 2 paramaters sent.

 

Unfortunately I have very little to no experience with javascript and ajax so your help would be greatly appriciated on this.

 

There is no point me pasting the code for the form itself as im not looking to use a form/dropdown box but I will paste the javascript code used at w3schools.

 

Javascript

var xmlHttp

function showUser(str)
{ 
xmlHttp=GetXmlHttpObject()
if (xmlHttp==null)
{
alert ("Browser does not support HTTP Request")
return
}
var url="getuser.php"
url=url+"?q="+str
url=url+"&sid="+Math.random()
xmlHttp.onreadystatechange=stateChanged 
xmlHttp.open("GET",url,true)
xmlHttp.send(null)
}

function stateChanged() 
{ 
if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
{ 
document.getElementById("txtHint").innerHTML=xmlHttp.responseText 
} 
}

function GetXmlHttpObject()
{
var xmlHttp=null;
try
{
// Firefox, Opera 8.0+, Safari
xmlHttp=new XMLHttpRequest();
}
catch (e)
{
//Internet Explorer
try
  {
  xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
  }
catch (e)
  {
  xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
  }
}
return xmlHttp;
}

 

could someone please help me change this so that I can click a link instead of a form and the link supplies 2 paramaters to the javascript code instead of just the 1

 

thank you very much for your help

 

regards

 

wayne

Link to comment
Share on other sites

@php.ajax.coder

 

thanks for the info, I was going to ask how to add the paramaters to that but did a little searching and found a few examples so managed to get it working great, even found out how to make it load the theme value when page is loaded.

 

thanks for the help

 

regards

 

wayne

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.