• 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Using jQuery + JSON + Struts to populate select options based on input textfield

 
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I am trying to implement an ajax call to populate the options of a select drop down based on the input textfield. However, i can generate the json file but i'm not able to populate the select form with the json result. Any help would be appreciated on this.


This is my method which allows us to get the template for a number .


And here is my jsp page :



But how can i populate select form with this data contained in json file ?

jsonResult.PNG
[Thumbnail for jsonResult.PNG]
Json result to populate the select form
 
Sheriff
Posts: 67746
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

Not able to" doesn't give us much to work with. Please read TellTheDetails and provide with more information.

Have you used the browser debugger to set breakpoints and look around at what's going on?
 
Ghiles bou
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Okay,
So i have to do one web application which interact with the database .
And the firstt thing to do is to allow user download template.

In this user interface , the user must enter a negociateur number (let call him simply number) and when we finished entering, we will have on the select form the list of all template available for this number.
I successed on doing json results which contains the list of the template for one number . But now i have to populate the select form whith this result when the user finished to complete the textfield and lost focus.
So i must have one fonction that populate the select form which i call on the textfield ( I can use onblur=function())
This is my struts.xml
UIDownload.PNG
[Thumbnail for UIDownload.PNG]
UserInterface
 
Bear Bibeault
Sheriff
Posts: 67746
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
So, what's not working? What do your debugging steps reveal? Are you getting the JSON back correctly? Where are things going wrong?
 
Ghiles bou
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
What's not working is that my select stay whith no value ;the picture of json results that i've added earlier are generate after i set the number in the console (i've done a system.out.println to be sure that they are in correct format and it seem to be ok) ..
I have looked on http://tech.learnerandtutor.com/dynamic-drop-down-list-with-struts2-ui-tag-without-ajax-jquery/ but in that tutorial the are two select form which is not what it asked to me ..
 
Bear Bibeault
Sheriff
Posts: 67746
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
You need to learn how to debug JavaScript. Open the browser debugger and learn how to use the Dev Tools. This is essential and not a tool you can do without.

Inspecting your code, you are not passing any data to your success handler, and the handler tries to call a function named getListeTemplateDownload that is not defined. What's that all about?

The JSON data will be parsed and the result will be passed to the success handler as the first argument. Also, why not use the $.getJSON() shortcut method which should shorten the code considerably?
 
Ghiles bou
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Sure i've created the method getListeTemplatedownload() ;
I've debugged and i've checked if the list is not empty and it's the case;
My list contains the value that i would to put on the select form.
How to use getJson() method? Should i modify my script and put only this method to get the json file...
I've not learn ajax, and it's just in this page that i must use this langage...
 
In the renaissance, how big were the dinosaurs? Did you have tiny ads?
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic