Ask a Question related to Coldfusion Database Access, Design and Development.

  1. #1

    Default two select advice

    Hi Am i on the right track
    I want to make a two related select between area and language
    The user chooses the area then in the second drop down menu the available
    language appears for that area.

    Example: Area ---->Central
    Language-----> English

    Russian
    -
    SUBMIT- List of available hospital in that area

    Question 1: Have I set up my tables correctly?

    Table 1
    Location_ID Area Area_Code
    1 ?????? ??
    2 ?????????Ku ??
    3 ????????? ??
    4 ???????? ??

    Table 2

    Language_id Language_name Languagecode
    1 ??????? eng
    2 ??????? rus
    3 ??????? spn
    4 ?????????? prt
    5 ?????? ???
    6 ??????? chn
    7 ??????? ???

    Table 3

    Hospital_ID Hospital_name Area_Code Language
    1 ?hospital ?? English
    2 ?hospital ?? English
    3 ?hospital ?? Russian

    Question 2: I was thinking of following this example that i found - is it
    appropriate?


    <!--- Select the states and area codes. --->
    <cfquery datasource="States" name="GetStates">
    SELECT S.State, S.StateCode, AC.AreaCode
    FROM States S, AreaCodes AC
    WHERE S.StateCode=AC.StateCode
    ORDER BY S.State, AC.AreaCode
    </cfquery>

    <!--- Select all the area codes. --->
    <cfquery datasource="States" name="GetCodes">
    SELECT AreaCode
    FROM AreaCodes
    ORDER BY AreaCode
    </cfquery>

    <script language = "JavaScript">
    <!--
    // For each state, create an array to hold the area codes.
    // Each state array will be identified by the two-character state abbreviation
    <cfoutput query="GetStates" group="State">
    // Create the array
    StateArray#StateCode# = new Array();
    <cfset i = 0>
    // Populate the array
    <cfoutput>
    <cfset i = i + 1>
    StateArray#StateCode#[#i#] = #AreaCode#;
    </cfoutput>
    </cfoutput>

    // Function to populate the area codes for the state selected
    function PopulateAreaCode() {
    // Only process the function if the first item is not selected.
    if (document.StateForm.StateCode.selectedIndex != 0) {
    // Find the state abbreviation
    var ThisState =
    document.StateForm.StateCode[document.StateForm.StateCode.selectedIndex].value;
    // Set the length of the arecode drop down equal to the length of the
    state's array
    document.StateForm.AreaCode.length = eval("StateArray" + ThisState +
    ".length");
    // Put 'Select' as the first option in the area code drop-down
    document.StateForm.AreaCode[0].value = "";
    document.StateForm.AreaCode[0].text = "Select";
    document.StateForm.AreaCode[0].selected = true;
    // Loop through the state's array and populate the area code drop down.
    for (i=1; i<eval("StateArray" + ThisState + ".length"); i++) {
    document.StateForm.AreaCode.value = eval("StateArray" + ThisState +
    "");
    document.StateForm.AreaCode.text = eval("StateArray" + ThisState +
    "");
    }
    }
    }
    //-->


    <form name="StateForm">
    <p>
    <table border="0">
    <tr>
    <td><b>State</b></td>
    <td><b>Area Code</b></td>
    </tr>
    <tr>
    <td>
    <select name="StateCode" onChange="PopulateAreaCode()">
    <option value="0">Select State
    <cfoutput query="GetStates" group="State">
    <option value="#StateCode#">#State#
    </cfoutput>
    </select>
    </td>
    <td>
    <select name="AreaCode" width="70" style="width:150" size="1">
    <option value="0">Select Area Code
    <cfoutput query="GetCodes">
    <option value="#AreaCode#">#AreaCode#
    </cfoutput>
    </select>
    </td>
    </tr>
    </table>
    </p>
    </form>

    quiero mas Guest

  2. Similar Questions and Discussions

    1. Select a list of items into an aliased field when doinga select
      OK I know this is going to sound weird, but I'm wondering if this is possible. I have a task table. (tblTask) These tasks can be assigned to...
    2. #25474 [Bgs]: posting arrays from a select box with multiple select is not working properly
      ID: 25474 User updated by: fmuller at cisco dot com -Summary: apache2filter: posting from a multiple select box is not...
    3. #25474 [Fbk->Opn]: posting arrays from a select box with multiple select is not working properly
      ID: 25474 User updated by: fmuller at cisco dot com Reported By: fmuller at cisco dot com -Status: Feedback...
    4. #25474 [Opn->Fbk]: posting arrays from a select box with multiple select is not working properly
      ID: 25474 Updated by: sniper@php.net Reported By: fmuller at cisco dot com -Status: Open +Status: ...
    5. SELECT DISTINCT + ORDER BY gives ERROR 145: ORDER BY items mustappear in the select list if SELECT DISTINCT is specified.
      Dan, You should be able to do this: SELECT Id, FaxID, ReceivedTime, Pages FROM ( SELECT DISTINCT .Id AS Id,
  3. #2

    Default Re: two select advice

    The way you have your tables set up, each hospital can have only one language.
    Is that what you want?

    Also, in table 3, I would use locationid rather than areacode as a field, and
    have a foreign key relationship to location.

    Also, I am not sure if your areacode field in location serves any useful
    purpose. For your drop down list, you can have a value of locationid and
    display the area.

    Dan Bracuk Guest

  4. #3

    Default Re: two select advice

    Thanks for the Advice Dan - Im still working on the sub string code as well - so might be posting some questions about that in the near future.

    Thanks again
    Mark
    quiero mas Guest

  5. #4

    Default two select advice

    I have been trying to create a two select but
    Something isn't quite working.

    Firstly im trying to populate the menus - but i get an error - page cannot be
    displayed
    first menu is location which in turn populates the second menu language then
    this will be used for a query.
    First i would like to get the menu populating



    Hospital_ID Hospital_Name Location_ID
    1 ????? 1
    2 ????? 1
    3 ????? 4

    Hospital_ID Language_ID
    1 1
    1 2
    1 6
    2 1
    2 6
    3 2
    3 1

    Language_IDLanguage_nameLanguage_code
    1 ??????? eng
    2 ??????? rus
    3 ??????? spn
    4 ?????????? ???
    5 ?????? ???
    6 ??????? ???
    7 ??????? ???

    Location_ID Area
    1 ?????
    2 ?????????
    3 ???????
    4 ??????

    ?????????( I have tried to follow an example i found on the net)


    <cfquery name="GetLocation" datasource="simple">
    SELECT tslocation.Area, tslanguage.Language_name
    FROM tslocation INNER JOIN (tslanguage INNER JOIN (tsHospital INNER JOIN
    tshsptlang ON tsHospital.Hospital_ID = tshsptlang.Hospital_ID) ON
    tslanguage.Language_ID = tshsptlang.Language_ID) ON tslocation.Location_ID =
    tsHospital.Location_ID</cfquery>

    <!--- Select all the area . --->
    <cfquery datasource="simple" name="GetLanguage">
    SELECT Language_name
    FROM tslanguage
    ORDER BY Language_name</cfquery>

    <script language = "JavaScript">
    <!--
    // For each Area, create an array to hold the Area.
    // Each Area array will be identified by the Area
    <cfoutput query="GetLocation" group="Location">
    // Create the array
    AreaArray#Area# = new Array();
    <cfset i = 0>
    // Populate the array
    <cfoutput>
    <cfset i = i + 1>
    AreaArray#Area#[#i#] = #Language#;
    </cfoutput>
    </cfoutput>

    // Function to populate the Language for the Location selected
    function PopulateLanguage() {
    // Only process the function if the first item is not selected.
    if (document.LocationForm.Location_ID.selectedIndex != 0) {
    // Find the Location
    var ThisLocation =
    document.LocationForm.Location_ID[document.LocationForm.Location_ID.selectedInde
    x].value;
    // Set the length of the arecode drop down equal to the length of the
    state's array
    document.LocationForm.Language.length = eval("LocationArray" +
    ThisLocation + ".length");
    // Put 'Select' as the first option in the area code drop-down
    document.LocationForm.Area[0].value = "";
    document.LocationForm.Area[0].text = "Select";
    document.LocationForm.Area[0].selected = true;
    // Loop through the state's array and populate the area code drop down.
    for (i=1; i<eval("LocationArray" + ThisLocation + ".length"); i++) {
    document.LocationForm.Area.value = eval("LocationArray" +
    ThisLocation + "");
    document.LocationForm.Area.text = eval("LocationArray" + ThisLocation
    + "");
    }
    }
    }
    //-->
    </script>



    <form name="LocationForm">
    <p>
    <table border="0">
    <tr>
    <td><b>Location</b></td>
    <td><b>Language</b></td>
    </tr>
    <tr>
    <td>
    <select name="Location" onChange="PopulateLanguage()">
    <option value="0">Select Location
    <cfoutput query="GetLocation" group="Location">
    <option value="#Location#">#Location#
    </cfoutput>
    </select>
    </td>
    <td>
    <select name="Language" width="70" style="width:150" size="1">
    <option value="0">Select Location
    <cfoutput query="GetLanguage">
    <option value="#Language#">#Language#
    </cfoutput>
    </select>
    </td>
    </tr>
    </table>
    </p>
    </form>

    quiero mas Guest

Posting Permissions

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

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139