• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Drop down from DataBase problem

 
mike mimmis
Ranch Hand
Posts: 57
Java MySQL Database Netbeans IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 65126
92
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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?
 
mike mimmis
Ranch Hand
Posts: 57
Java MySQL Database Netbeans IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 65126
92
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 57
Java MySQL Database Netbeans IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 21
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 57
Java MySQL Database Netbeans IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 65126
92
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
    Posts: 21
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    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
    Posts: 57
    Java MySQL Database Netbeans IDE
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    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
    Posts: 445
    1
    Java Spring
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator

    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
    Posts: 41
    Eclipse IDE Firefox Browser Java
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    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. :-(
     
    krunal prajapati
    Greenhorn
    Posts: 19
    Eclipse IDE Java Tomcat Server
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    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
    Posts: 57
    Java MySQL Database Netbeans IDE
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    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...
     
    • Post Reply
    • Bookmark Topic Watch Topic
    • New Topic