PHP, MySQL & ajax with data on default page
default page is empty when page first load.
how can i show data on default page? i mean when page first load i want to show all data then do the ajax after user select to filter

Example is based off of:
using code posted by vibhaJ

    <script type="text/javascript">
    function showUser()
    var users = document.getElementById('users').value;
    var sex = document.getElementById('sex').value;
    if (users=="" && sex=="")
    if (window.XMLHttpRequest)
    {// code for IE7+, Firefox, Chrome, Opera, Safari
    xmlhttp=new XMLHttpRequest();
    {// code for IE6, IE5
    xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
    if (xmlhttp.readyState==4 && xmlhttp.status==200)
    <select name="users" id="users" onChange="showUser()">
    <option value="">Select a person:</option>
    <option value="1">Peter Griffin</option>
    <option value="2">Lois Griffin</option>
    <option value="3">Glenn Quagmire</option>
    <option value="4">Joseph Swanson</option>
    <select name="sex" id="sex" onchange="showUser()">
    <option value="">Male/Female:</option>
    <option value="1">All</option>
    <option value="2">Male</option>
    <option value="3">Female</option>
    <div id="txtHint"><b>Person info will be listed here.</b></div>

Recommended Answers

All 2 Replies

could use:

<script type='text/javascript'>showUser();</script>

Just before body closes, you will need to set peter griffin and the all options selected for it to run as well(<option value='1' SELECTED>Peter griffin</option>). Or you could just put a mysql query into the php to pull the data you want to show on page load.

i tried putting value

 <select name="users" id="users" onChange="showUser(<option value='1' SELECTED>Peter griffin</option>)">

      <option value='1' SELECTED>Peter griffin</option>

doestnt work

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, learning, and sharing knowledge.