Jump to content

auto loading data from a selected value on page load php ajax db


chen2424

Recommended Posts

Hi guys,

 

ive used the this ajax db code tutorial from http://www.w3schools.com/php/php_ajax_database.asp and it works well. Problem is this, in the example, assuming we put <option selected value="1">Peter Griffin</option> , how do we get the page to load peter griffins data automatically?

 

If you observe when you enter the page, peter griffin is shown but not loaded. Youll have to select something else and go back to reselect peter grifin in order to load data. How can we autoload this on page load or refresh? Many thanks in adv to anyone who knows.

 

kind rgds, Chen

Link to comment
Share on other sites

Hi,

Personally, if you have the id of the user on page load, I would get the data using php rather than using ajax.

Alternatively, you could call the javascript function on page load, passing it the id of the user:

 

eg. (where 1=id of user)

onload="showUser(1)"

 

Chris

Link to comment
Share on other sites

Hi Cbolson.

 

thanks for yr reply , ive tried that,. :

<form>
Select a User:
<select name="users" onload="showUser(1)" onchange="showUser(this.value)">
<option selected value="1">Peter Griffin</option>

 

This doesnt solve the issue, peter still doesnt load on page load strangely,. any ideas why? Thanks in advance!

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.