SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Member
    Join Date
    Oct 2010
    Posts
    18
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Question problem in selecting second arraylist from mysql database

    Hi...everyone
    Below i have attached my code. This code is working.....but i want some modification in that code such that when i select 'vegetable' or 'fruits', it should give list of that selected one in second list, BUT THAT list should be stored in mysql database.
    In the below program , i have hard-coded that second list, but i want second list to be dynamic from database.

    Please, help me out.
    Thank you for your help in advance
    Code:
    <HTML>   
    <HEAD>   
    <SCRIPT LANGUAGE="JavaScript">   
    <!--Begin JavaScript   
      
      
      
    function setList(f) {   
     secondlist=eval("'"+f.elements['list1'].options[f.elements['list1'].selectedIndex].text+"'");   
     f.elements['list2'].options.length=0;   
     size=eval("lists['"+secondlist+"'].length");   
     for(i=0;i<size;i++) {   
      newval=eval("lists['"+secondlist+"'][i]");   
      f.elements['list2'].options[i]=new Option(newval);   
     };   
      f.elements['list2'].selectedIndex=0;   
    };   
    lists=new Array();   
    lists['Fruit'] = new Array();   
      lists['Fruit'][0]="apple";   
      lists['Fruit'][1]="banana";   
      lists['Fruit'][2]="cantelope";   
      lists['Fruit'][3]="grape";   
      lists['Fruit'][4]="honeydew";   
      lists['Fruit'][5]="kiwi";   
      lists['Fruit'][6]="lemon";   
      lists['Fruit'][7]="lime";   
      lists['Fruit'][8]="mango";   
      
      
    lists['Vegetables'] = new Array();   
      lists['Vegetables'][0]="carrot";   
      lists['Vegetables'][1]="celery";   
      lists['Vegetables'][2]="onion";   
      lists['Vegetables'][3]="potato";   
      lists['Vegetables'][4]="squash";   
      lists['Vegetables'][5]="tomato";   
      
      
    //End JavaScript-->   
    </SCRIPT>   
    <BODY BGCOLOR=WHITE onLoad="setList(document.listsform)">   
      
    <FORM NAME="listsform">   
    <SELECT NAME="list1" onChange="setList(form)">   
    <OPTION>Fruit</OPTION>   
    <OPTION>Vegetables</OPTION>   
      
    </SELECT>   
      
    <SELECT NAME="list2">   
    <OPTION>         </OPTION>   
    <OPTION></OPTION>   
    <OPTION></OPTION>   
    <OPTION></OPTION>   
    <OPTION></OPTION>   
    <OPTION></OPTION>   
    <OPTION></OPTION>   
    <OPTION></OPTION>   
    <OPTION></OPTION>   
      
    </SELECT>   
    </FORM>   
    </BODY></HTML>

  2. #2
    SitePoint Wizard bronze trophy chris.upjohn's Avatar
    Join Date
    Apr 2010
    Location
    Melbourne, AU
    Posts
    2,197
    Mentioned
    17 Post(s)
    Tagged
    1 Thread(s)
    You would need to use Ajax to achieve this, the best solution would be to use Ajax with JSON which will allow for easier data management for the return data.

    Read this article for more information about Ajax and for the JSON library you would need the javascript source and the PHP source if your going to use PHP.

    JSON JS: https://github.com/douglascrockford/JSON-js
    JSON PHP: http://www.php.net/releases/5_2_0.php

  3. #3
    SitePoint Wizard bronze trophy chris.upjohn's Avatar
    Join Date
    Apr 2010
    Location
    Melbourne, AU
    Posts
    2,197
    Mentioned
    17 Post(s)
    Tagged
    1 Thread(s)
    Sorry posted the wrong link for JSON PHP http://php.net/manual/en/function.json-encode.php


Bookmarks

Posting Permissions

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