I need to populate a drop down list in a jsp page form using the values fetched from the database. The condition is only few rows are fetched from the database based on the other fields of the form. How do i do this without using jQuery or other stuff? I'm quite new to coding, so i require help.
The scenario is, based on employee id entered, the state of the employee has to fetched from the database. And then based on the state fetched from database i need to create a drop down list containing the different office branches present in that state from the database. I dont want multiple pages for taking these details, just one form in a page. How to i populate such a dropdown box in a jsp page?
Either you have to go for jquery or AJAX which will populate your
data without an actual servlet request, or you have to do this
in two different forms.
Related
I'm planing to create generic form created dynamically with JSON data from server.
Assume a ng form, using ng repeat we populating dynamic form, based on the first set of JSON.
If the form has drop-down or radio elements there should be another call to get subset elements (textbox, radio) to populate under the parent drop down or radio.
If drop-down changes, sub form should be added under the parent drop down.
There is no workflow using those data. Only CRUD Operations are performed.
I'm planing this to do generically from angular controller till db design level.
How the db/service design should be for making Json for parent set?
How to link the parent and sub set even sub's subset?
How to save the data and do edit operation?
Also is it better idea to save data as Json in db column?
I am not sure if I understood your question but if you have an option to display a form from a set of forms, you can just create templates of those forms and display them on the dropdown select.
If it is a generic form template then I guess you only have to change the labels and the form names in those html templates. You can bind the values to the same model names to ng-model in the controller.
DB design depends on the nature of data you have, which you have not mentioned, so its tough to answer.
'JSON data' is the payload passed through your REST services. That has to do with how you design your response data. If its just form-templates details for the form suggested you've selected in the dropdown, then you can just pass the label names and data types for those fields.
So there will be 2 services.
1. A GET to get the Form template labels and field definitions.
2. A POST to submit the form.
Keep in mind that all these forms are defined at the beginning and not created on the fly. i.e you cannot create a new form-template on the fly.
I am trying to add multileg travel information using PHP, jQuery and MySQL. I present to users with existing data and then they dynamically add travel leg information to their existing visit. What I have done so far is below.
Bind data (PHP -MySQL) to the HTML table. Show add new button the user.
When the user clicks on add new, I have used jQuery to clone the data and this has dynamic id.
On the form there is file upload as well which needs to upload the file and also save information in the database.
My problem is how can I rebind the data on the table without effecting any other thing. I have tried to use jQuery load but it tries to reload the entire page rather than just reloading the newly generated trs.
I am open to change my logic on the whole as to how I do this.
Appreciate any help on this.
I have a dropdown, on its change I need to load the contents related to it on the same page. Which I did using jQuery. Now the question is how do I make edits on this data and store it on my database. If I am wrong in using jQuery for loading my data then what else should I use? I am using PHP as my server side scripting language.
More detail -
Simply taking there a list of details I need to display as per the country you select, which I am displaying currently in a nice grid(textboxes)!
Now the data from this grid should be copied to another textbox on "EDIT" button click from where I edit them and store it in my database. I am not able to make the values copy into a another textbox
You could do this:
Display the data in some form of editable div, textarea, or other element.
Make a hidden field somewhere and when you display the data
Set the row id from your database to the hidden field
On your change event, grab the id from the hidden field along with the edited data.
Using Jquery/ajax, send that data to a php page that will save thee data to your database using the passed in id.
You could do that.
However, if it were me (and if you're not married to your current databse / mySQL etc..), I would use parse.com. The service is free up to a significant amount of usage (which Ive never come close to) and it really simplifies everything. See the below post if you're interested in that approach:
Save and retrieve user input from database with javascript?
I'm having a page where I can create some configuration sections and the page is structured as follows:
It has a button that adds a partial view to the page (using an AJAX call) and on this partial view I have:
Dropdown to select the section
List of available items
List of selected items
The list of selected items is populated using jQuery UI (sortable) via drag&drop. The items above can be repeated as much as the user wants. And I want to pass to the controller the data selected from all the dropdowns and from all the lists of selected items.
I have no idea how I can use a #model or even the ViewBag because the selected items list is initially empty and gets populated on the client side. As a side note, I don't need the list of available stuff.
UPDATE:
I've changed the question because I'm willing to put all the data in a form and I gave up the idea to use javascript to collect the data and make a request to my controller. So now I'm trying to use the FormCollection to get the data. The only problem is that when I submit the form FormCollection has no data in it.
UPDATE 2:
After looking into the FormCollection and ModelBinding I've came upon an impediment. I can't get the items on the form that don't have the name property. The problem is that the <ul> or <li> elements don't have the name attribute. So the question would be, how can I get the data from those elements using the above mentioned methods if they don't have name ?
I have found the solution: I gave up on using lists and moved to using the select multiple with the ui.multiselect plugin. This solved the problem as the select has the name attribute and I can get the data using FormCollection.
I am looking a sample for the functionality where there are 2 drop downs. One is 1 is State/Province and the 2rd is City. Based on the state drop down selection, city drop down values should be populated.
I need sample database design also....
Could anyone please help me out on getting a sample for this.
Regards
padman..
With neither Ajax nor refreshes? Bad idea, unless you have a very limited number of state/city combinations--otherwise the HTML/JavaScript you send will be huge.
Otherwise it's a simple dependent select, which is searchable on the web. The nutshell version is that when your state changes, you take the value of the selected state option, use it to look up cities in a map of state id => cities, and use the cities collection to populate the second select box.
The state/cities JavaScript structure is created on the server side using whatever template mechanism the rest of the app uses (I assume JSP or Velocity since you're using Struts 1).
DB DB design for what? States and cities? Have a table of states. Have a table of cities with a state id foreign key.