chen2424 Posted October 25, 2009 Share Posted October 25, 2009 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 https://forums.phpfreaks.com/topic/178930-auto-loading-data-from-a-selected-value-on-page-load-php-ajax-db/ Share on other sites More sharing options...
cbolson Posted October 25, 2009 Share Posted October 25, 2009 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 https://forums.phpfreaks.com/topic/178930-auto-loading-data-from-a-selected-value-on-page-load-php-ajax-db/#findComment-944018 Share on other sites More sharing options...
chen2424 Posted October 25, 2009 Author Share Posted October 25, 2009 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 https://forums.phpfreaks.com/topic/178930-auto-loading-data-from-a-selected-value-on-page-load-php-ajax-db/#findComment-944025 Share on other sites More sharing options...
cbolson Posted October 25, 2009 Share Posted October 25, 2009 you need to add it to the page load (eg in the <body> tag). Link to comment https://forums.phpfreaks.com/topic/178930-auto-loading-data-from-a-selected-value-on-page-load-php-ajax-db/#findComment-944026 Share on other sites More sharing options...
chen2424 Posted October 25, 2009 Author Share Posted October 25, 2009 Cheers Cbolson! it works great! Link to comment https://forums.phpfreaks.com/topic/178930-auto-loading-data-from-a-selected-value-on-page-load-php-ajax-db/#findComment-944028 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.