Go Back   CodingForums.com > :: Client side development > JavaScript programming

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 04-30-2008, 07:57 PM   PM User | #1
snh
New to the CF scene

 
Join Date: Apr 2008
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
snh is an unknown quantity at this point
Jump Menu Dynamic Drop Down Menu

Hello,

I have a coded two drop down boxes which pull information from a MySQL database. I am currently using a javascript jump menu to refresh the page, which then generates the second drop down box (based on the selection in the first drop down box). My question is that when the page refreshes all my previous data is lost. Do you know of any way in which I can retain the values within the rest of my form? Any suggestions would be great! Thanks

Here is the jump menu code I am using:


Code:
    <script language="JavaScript" type="text/JavaScript">
    <!--
    function MM_jumpMenu(targ,selObj,restore){ //v3.0
      eval(targ+".location='"+"Pratt_Instance_1.php?mcate="+selObj.options[selObj.selectedIndex].value+"&mind="+selObj.selectedIndex+"'");
      if (restore) selObj.selectedIndex=0;
    }
    function MM_jumpMenu2(targ,selObj,restore){ //v3.0
    eval(targ+".location='"+"Pratt_Instance_1.php?mcate="+selObj.options[selObj.selectedIndex].value+"&mind="+selObj.selectedIndex+"$cate="+selObj.options[selObj.selectedIndex].value+"&ind="+selObj.selectedIndex);
      if (restore) selObj.selectedIndex=0;
    }
    //-->
    </script>


and the drop down box SQL code


Code:
   <select id="Instance_Type111" name="mcate" onchange="MM_jumpMenu('parent',this,0)">
                <option value="0">Select</option>
    <?php

                // Get the Categories from Database
                if (!isset($type_array)){
                 $type_array=get_category_name();

                $query = "SELECT Type_ID, Type_Name FROM Instance_Type111";
                   $query_result=@mysql_query($query,$mysql_link)
                         or die ('Could not get categories! <br>\n');
                   $type_array = db_result_to_array($query_result);
                   }
             // Display Categories in the menu listing
                $mi=1;
                foreach ($type_array as $row){
                $Type_ID= (string) $row['Type_ID'];
                $Type_Name= $row['Type_Name'];
                if ($mi!=$mind){
                print ("<option value=$Type_ID>$Type_Name</option>");
                } else {
                print ("<option value=$Type_ID selected>$Type_Name</option>");
                }
                     $mi++;
                }

                // Setting the main category code
          // $mcate_code is the maincat_id of main category chosen
             if(!isset($HTTP_GET_VARS['mcate']))   {
               $mcade_code = 0;
              } else{
               $mcade_code =  $HTTP_GET_VARS['mcate'];
             }
    ?></select></td>
                   </tr>
    <tr>
    <td>
    Detailed Incident Type:
    </td>
    <td >
    <select name="cate" id="Detailed_Instance_LUT111" onChange="MM_jumpMenu2('parent',this,0)">
    <option value="0"  >Select</option>
       <?php
    //Get Detailed Definition from Database
       $type_array=get_categories($mcade_code);
    // Display Categories in the menu listing
       display_category($type_array);

    // Setting the main category code
          // $cate_code is the maincat_id of main category chosen
             if(!isset($HTTP_GET_VARS['cate']))   {
               $icade_code = 0;
              } else{
               $icade_code =  $HTTP_GET_VARS['cate'];
             }
    ?></select></td>


Thanks
snh is offline   Reply With Quote
Old 04-30-2008, 08:33 PM   PM User | #2
Ancora
Banned

 
Join Date: Oct 2005
Location: I'm in GMT -5
Posts: 314
Thanks: 0
Thanked 1 Time in 1 Post
Ancora is on a distinguished road
See attached .zip file.

AJAX Dynamic Select List with PHP and MySQL.

Selected option in the first list, determines the options that populate a second list, which are retrieved from a MySQL database.
Attached Files
File Type: zip AJAX Dynamic Select List with PHP and MySQL.zip (2.7 KB, 384 views)
Ancora is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 07:27 PM.


Advertisement
Log in to turn off these ads.