PHP and Javascript - On select change fill in 2 further selects - javascript

I have a SQL datatable with 4 fields of info for a list of "Hazards":
ID
HazardName
DefaultInjury
DefaultSeverity
I have a form with 3 dropdowns (selections). The 1st 1 is filled in via AJAX with the ID and HazardName. The other 2 selections are filled with values and labels from other data tables.
What I want to do.. is when I select a hazard (on change) I want to set the 2nd selction with the DefaultInjury value and the 3rd selection with the DefaultSeverity value.
Is there an easy way to do this, such as having hidden extra values in the selections?
What I'm trying to avoid is having to use AJAX again to retrieve the values from the database again.
Thank you in advance for any help.

Related

Populating listbox with a function that gets values from a table

I have 2 listboxes on my web page. I want to populate second listbox by a value selected in first list box. When I select an option in firstlistbox it queries a table on my backend and populates the secondlist box based on the results. I cannot use php script inside a javasript so what should I do?
You are asking how create a sub categories list box. You need create it easily using AJAX.
Here are the steps you need to do.
Populate first list box and call function loadData() when you change item.
send ajax request to getdata.php with selected category_Id parameter
Make getdata.php to output second list box according to category_Id
Display ajax response on page as html
I found this article for you.
Hope it helps.

Data in multiple dropdowns

I have a form which contains 10 dropdown controls. Each control will be populated with the same 20 rows of data which are selected from a db table.
What I want to do is ensure that when the final choice is made there are no duplicates.
I could easily just do some error checking when I save the data, but maybe there is a slick way of hiding or graying out the items once they are chosen with javascript.
Has anyone done anything like this?
You could remove items from the other dropdowns when an item is selected in one. So other dropdowns want have that item for selection.

Populate Kendo DropDownList with array from selected value

Using javascript I want to populate a dropdownlist (DDL2) with certain data from a REST JSON endpoint based on the selected value of the DDL2.
This DDL2 selected value is triggered by previous DDL1 selection (I have that part working). For example if DDL1 selected value is "Town" then the selected value for DDL2 is: "SELECT towninfo FROM towns ORDER BY towninfo". It's a SQL query, currently. I have the option of replacing it with a comma-delimited array of towns (RALEIGH,CHARLOTTE,ASHEVILLE...), or I could replace it with a JSON string. I'm open for suggestions on that part.
What I want to do is populate DDL2 with the selected array. So when I select "Towns" in DDL1 then DDL2 populates with a list of towns. Thanks!
If you mean something simple as populating a second drop down based on the first one's selection, here is a quick and dirty sample...
http://jsbin.com/AHOpAJA/1/edit
If you want something a bit more complicated, here is another one using three dropdowns, that all bind from a service. http://jsbin.com/ihodoc/3/edit

Validate that dropdown values are all distinct from one another with Javascript and/or Jquery?

I have a form with 7 dropdowns, all containing the values 1-7.
What is the easiest way to validate (using a function) that all of the "selected" values are distinct from one another using Javascript and/or Jquery?
Thanks in advance.
Create array that contains 1-7 values
In first dropdown add all these 7 values
On the "OnSelect" event of the first dropdown remove the selected value from array and add the array in 2nd dropdown.
This will add all the values in 2nd dropdown except the one selected in first dropdown
Continue for all the 7 dropdowns

javascript: how to make multiple combo boxes with same data

i have a scenario in JSP where i have to make a combo with a list containing 10 items say 1,2,3.... 10. now i select a combo. I also need to provide an add button that will add another combo with same elements except the one being selected in previous combo.
eg- if 1st combo selected value is 1 then in the next combo i'll have the list as 2,3,4.....10 i.e, having 9 elements and so on. the user can add 10 combos like this, each combo having the items that haven't been previously selected.
can anyone help me with this???
thanks in advance :) !!!
just to clear things out, your scenario is that you have 10 combo boxes that contain values from 1 to 10... i suggest you can use a case statement, or multiple if statements, you can use javascript for that...

Categories