File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes JSP and the fly likes Drop down from DataBase problem Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » JSP
Bookmark "Drop down from DataBase problem" Watch "Drop down from DataBase problem" New topic
Author

Drop down from DataBase problem

mike mimmis
Ranch Hand

Joined: Feb 11, 2011
Posts: 57

Hi ranchers,

I am developing an application using servlets and Jsp. I have 2 drop down menu's. in first drop down menu i am retrieving Countries names from MySql Database. based on selection of country in second drop down states will come in second. I have done it by using Ajax. but my project manager told to do not use ajax. Just use simple java/ javascript.

How can i achieve this...


example:

country:

states:

how can i achieve it in jsp by using servlets/ java/ javascript. but not using Ajax...



Thanks & Regards,

Mike....
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61001
    
  65

Then you'll need to submit the entire page and recreate it with the new options.

What possible reason for "JavaScript is OK, but Ajax is not" could your project manager have?


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
mike mimmis
Ranch Hand

Joined: Feb 11, 2011
Posts: 57

Thanks for your reply....

I don't know the reason sir. but I have to do it by using java script but not with Ajax . The 2 drop down menu must be in a single page like

Country: States:


submit
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61001
    
  65

Unless you can preload all of the possible values into JavaScript constructs on the page, you will not be able to do this with just JavaScript.

Find out the reason -- I'm curious. I cannot think of a single valid reason that JavaScript is OK, but Ajax is out.
mike mimmis
Ranch Hand

Joined: Feb 11, 2011
Posts: 57

Sir ,

my project manager told that the Client requires to do it in JavaScript.. so how can i achieve this . without loading all values into javascript constructs is it not possible to achieve this . any other alternatives to do it dynamically..

Thnaks in advance....
rajarshi roy
Greenhorn

Joined: Feb 14, 2010
Posts: 21
Hope this will help............

Let us assume that the table storing details of the country and state name is location_table

mike mimmis
Ranch Hand

Joined: Feb 11, 2011
Posts: 57

Thanks for reply . I already done the above code...

what i need is when i select country name from that list the states will automatically populate in second drop down menu which came from MySql database . i.e when i select india it should populate like bangaloor,chennai....etc...
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61001
    
  65

Ajax is JavaScript, so your manager's reason makes no sense.

Again, without Ajax you'll either need to:

  • relaod the entire page adding the new otions
  • preload all of the possible values in a huge JavaScript construct


  • Neither approach is very good when Ajax handles this so well.

    I'm beginning to think your manage is rather clueless.
    rajarshi roy
    Greenhorn

    Joined: Feb 14, 2010
    Posts: 21
    mike mimmis wrote:Thanks for reply . I already done the above code...

    what i need is when i select country name from that list the states will automatically populate in second drop down menu which came from MySql database . i.e when i select india it should populate like bangaloor,chennai....etc...


    You will have to use InnerHTML,or Ajax for that,if you want to do that without refreshing the page,I will prefer Ajax.If a page-refresh is not an issue,then you can call a javascript onchange function,that will submit the page.Based upon what you have selected in the previous drop down menu ,you can pass the parameter to another query,which will populate the next drop down menu.
    mike mimmis
    Ranch Hand

    Joined: Feb 11, 2011
    Posts: 57

    rajarshi roy wrote:
    mike mimmis wrote:Thanks for reply . I already done the above code...

    If a page-refresh is not an issue,then you can call a javascript onchange function,that will submit the page.Based upon what you have selected in the previous drop down menu ,you can pass the parameter to another query,which will populate the next drop down menu.



    ya i can use onchange() function how to pass this variable within single page i need that drop down menu. i.e

    is there any way to convert javascript variable to java variable.. if any please provide me details....


    Thanks & Regards,

    Mike....
    Rajkamal Pillai
    Ranch Hand

    Joined: Mar 02, 2005
    Posts: 443
        
        1


    How about loading all the values when the page loads? I am thinking about loading up the page with [Country] values and also the values for the second drop-down. Then based on the value selected for the first drop-down (Country) you could change the options available in the second drop-down using Javascript. This would to change the options in the second drop-down without having to reload the page.
    Ashutosh M Kulkarni
    Ranch Hand

    Joined: Jun 07, 2010
    Posts: 41

    Of course there are workarounds for every possible sticky situation that our work could put us in.
    But as Bear already said, it is all unnecessary or rather pointless when Ajax can handle it amazingly well.

    I feel for you because it looks like you've been assigned a Functional background lead, technical person wouldn't have such an opinion. :-(


    SCJP 6, next stop - OCPJWCD!
    krunal prajapati
    Greenhorn

    Joined: Apr 18, 2011
    Posts: 19

    Hello all friends,

    I have done it upto two level with use of jsp,servlet and javascript (Not ajax),
    like,

    when you will select country, then its corresponding state will come, and when you will choose state then district name will come, but it become very complex, because of when page will reload ,previous value (country, state)also should be maintained,

    mike mimmis
    Ranch Hand

    Joined: Feb 11, 2011
    Posts: 57

    krunal prajapati wrote:Hello all friends,

    I have done it upto two level with use of jsp,servlet and javascript (Not ajax),
    like,

    when you will select country, then its corresponding state will come, and when you will choose state then district name will come, but it become very complex, because of when page will reload ,previous value (country, state)also should be maintained,



    can you attatch code. It is more helpful for me....

    Thanks and Regards,

    Mike...
     
    I agree. Here's the link: http://aspose.com/file-tools
     
    subject: Drop down from DataBase problem