www.webdeveloper.com
Results 1 to 3 of 3

Thread: i need help in javascript function :S !

  1. #1
    Join Date
    May 2012
    Posts
    4

    Question i need help in javascript function :S !

    i need help in javascript function :S !
    ---------------------------------------------
    hi guys,
    i need help in this thing :
    i have 2 '<select></select>'

    1 for the main category | and | 1 to sub category

    how can i allow automatic refresh and change to the sub category if i choose a main category ?

  2. #2
    Join Date
    Apr 2012
    Posts
    22
    use the onchange event of the main category and either refresh the page or use ajax to get the html only of the subcatecory select

  3. #3
    Join Date
    May 2012
    Posts
    4

    Exclamation jquery ajax

    i used the ajax:
    PHP Code:
    <?php
    require_once("base2.php");
    ?>
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
    <html>
     <head>
      <title> New Document </title>
      <meta name="Generator" content="EditPlus">
      <meta name="Author" content="">
      <meta name="Keywords" content="">
      <meta name="Description" content="">
    <script src="jquery-1.7.2.min.js" type="text/javascript" charset="utf-8"></script>
    <script type="text/javascript">
    $(document).ready(function(){



    $('#maincategory').change(function() {
    var id= $(this).val();
    $.ajax({  
                    type: "POST",
                   url:'subcat.php', 
                   data: "aid="+id+,   
                   success: function(data) {
                                if(data){
                                              
                               jQuery("#childcategory").html(data) ;
                                           }
                    }  
                });  




    })
    </script>
     </head>

     <body>
      

    <form action="" method="post">
    <select id="maincategory">
    <?php
                                                                    mysql_query
    ("SET NAMES 'utf8'");
                                                            
    $result2 mysql_query("SELECT Id as value,category_name as title FROM categories");
                                                            while(
    $row mysql_fetch_assoc($result2)){
                                                                    
    extract($row);                                  
                                                                    
    ?>
                                                                    <option value="<?=$value?>"><?=$title?></option>
                                                                    <?php
                                                            
    }
                                                            
    ?>
    </select>

    <select id="childcategory">

    </select>

    </form>
     

     </body>
    </html>
    and this is the: subcat.php
    PHP Code:
    <?php
    include 'base2.php';
    $cat =mysql_real_escape_string($_POST['aid']);
                                                                    
    mysql_query("SET NAMES 'utf8'");
                                                            
    $result22 mysql_query("SELECT sub_id as value2,sub_name as title2 FROM sub_categories WHERE category_full=".$cat);
                                                            while(
    $row2 mysql_fetch_assoc($result22)){
                                                                    
    extract($row2);                                  
                                                                    
    ?>
                                                                    <option value="<?=$value2?>"><?=$title2?></option>
                                                                    <?php
                                                            
    }
                                                            
    ?>

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles