www.webdeveloper.com
Results 1 to 5 of 5

Thread: Select 2 based on selected value in select1 - data for select2 comes from a database

  1. #1
    Join Date
    Aug 2004
    Location
    Australia
    Posts
    3

    Select 2 based on selected value in select1 - data for select2 comes from a database

    Hi All,

    This is the scenario:
    The first select has hard coded options - names of car makes.

    onChange triggers a JavaScript function. This function must now access a JavaBean available in the same JSP page this form is on, on the server and get a String[] of models back. The JavaScript function mentioned then uses this String[] to populate the options in the second select. I am OK once I get the String[] back.

    How do I:
    1)Access the JavaBean on the server and pass the parameter carMake from the JavaScript function?
    2)How do "receive" the returned String[]?

    I read about LiveConnect and studied it. I don't want to use applets as many people don't Java Enable their browsers.

    LiveConnect seems to be between JS and Applets. I am not sure if it will work here and if it will, how do I use it?

    Thanks,

    Chris

  2. #2
    Join Date
    Jul 2003
    Location
    Wales
    Posts
    1,382
    One problem, Javascript was not designed to handle database stuff.
    It can but it requires IE to do so and a pretty deep knowldge of ActiveX.

  3. #3
    Join Date
    Aug 2004
    Location
    Australia
    Posts
    3
    Thanks Ryan.

    It was starting to apear this way to me. Something for Netscape and Sun to work on.

    Chris

  4. #4
    Join Date
    Jul 2003
    Location
    Wales
    Posts
    1,382
    Well,

    if you use PHP to do the "dirty-work" then you can do it something like so:

    Code:
    <?php
      # Statements to deal with SQL extraction here
      $Result = "SELECT * FROM `Computers` WHERE `ID` = 1";
    ?>
    <script type="text/javascript">
      <!--
        var Result = <?php echo "$Result"; ?>;
      //-->
    </script>

    Hope that helps,

    RyanJ

  5. #5
    Join Date
    Aug 2004
    Location
    Australia
    Posts
    3
    Thanks Ryan,

    What you propose loads on page open. JSP can do the same:

    <script language="JavaScript">
    var CountriesArray = new Array();
    var counter = 0;
    <% java.util.Collection collection = countriesBean.getCountries();
    java.util.Iterator iter = collection.iterator();
    for(int x = 0; x < countries.length; x++){
    String country = (Country)iter.next();%>
    CountriesArray[counter] = <%=country%>;
    counter ++;
    <%}%>
    </script>

    I have decided to go this way. I'll keep all the data once loaded in a frame at the top from where one makes the selections. The results will appear in a frame below. Only the results will update.

    Seems JSP and PHP are on a par on this one.

    Regards,

    Chris

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