Enable multiple checkboxes in a page

Discussion in 'PHP' started by drors30, Jan 13, 2008.

  1. #1
    Hi all,
    The following question is based on a sample appears at w3schools at :
    http://www.w3schools.com/php/php_ajax_database.asp

    I want to build a similar page but instead of one check box i will have 3-4 check boxes
    in one page.
    Each of them will call a different Javascript that goes through a different php page and displays the
    results of the query in a different table.

    How can i achieve this ?
     
    drors30, Jan 13, 2008 IP
  2. barts2108

    barts2108 Guest

    Messages:
    18
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #2
    I would say to create 4 functions

    <select name="users" onchange="showUser1(this.value)">
    ....

    <select name="users" onchange="showUser2(this.value)">
    ....

    <select name="users" onchange="showUser3(this.value)">
    ....

    <select name="users" onchange="showUser4(this.value)">
    ....

    And modify the functions to fit your needs.

    On the server you can create 4 php files.. one for each
    combo box on your page. If you prefer to keep only one
    php file you can add another variable in the call to the
    php file

    from the w3schools example

    var url="getuser.php"
    url=url+"?q="+str

    would be something like: (function 1)

    var url="getuser.php"
    url=url+"?func=1&q="+str

    function2
    var url="getuser.php"
    url=url+"?func=2&q="+str

    etc.

    in the php file you can distinguish between the different calls
    by looking at

    if ($_GET['func'] == 1)
    {// code for function 1}
    if ($_GET['func'] == 2)
    {// code for function 2}
    if ($_GET['func'] == 3)
    {// code for unction 3}
    if ($_GET['func'] == 4)
    {// code for function 4}

    Or if you not like too many 'if' statments

    swtich($_GET['func'])
    {
    case 1:
    //code for function 1
    break;
    case 2:
    //code for function 2
    break;
    case 3:
    //code for function 3
    break;
    case 4:
    //code for function 4
    break;
    default:
    //code for non-existing function code
    break;

    }
     
    barts2108, Feb 9, 2008 IP