• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • paul wheaton
  • Liutauras Vilda
  • Ron McLeod
Sheriffs:
  • Jeanne Boyarsky
  • Devaka Cooray
  • Paul Clapham
Saloon Keepers:
  • Scott Selikoff
  • Tim Holloway
  • Piet Souris
  • Mikalai Zaikin
  • Frits Walraven
Bartenders:
  • Stephan van Hulst
  • Carey Brown

Drop down from DataBase problem

 
Ranch Hand
Posts: 57
Netbeans IDE MySQL Database Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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....
 
Sheriff
Posts: 67752
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Netbeans IDE MySQL Database Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Sheriff
Posts: 67752
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Netbeans IDE MySQL Database Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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....
 
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Netbeans IDE MySQL Database Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Sheriff
Posts: 67752
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
      Number of slices to send:
      Optional 'thank-you' note:
    • 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
    Netbeans IDE MySQL Database Java
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • 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....

     
    Ranch Hand
    Posts: 479
    1
    IntelliJ IDE Spring Java
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • 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.
     
    Ranch Hand
    Posts: 41
    Eclipse IDE Firefox Browser Java
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • 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. :-(
     
    Greenhorn
    Posts: 19
    Eclipse IDE Tomcat Server Java
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • 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
    Netbeans IDE MySQL Database Java
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • 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...
     
    I miss the old days when I would think up a sinister scheme for world domination and you would show a little emotional support. So just look at this tiny ad:
    We need your help - Coderanch server fundraiser
    https://coderanch.com/wiki/782867/Coderanch-server-fundraiser
    reply
      Bookmark Topic Watch Topic
    • New Topic