Advice or help accessing object items. |
Hello!
I am fairly new to Codeigniter and have come up against something that is alluding me. Perhaps it's the time of day, or that my code isn't as elegant as it could be. Summary of problem. I have a view that has a dependent dynamic dropdown. When you select from first dropdown, a java function makes an ajax call to a controller function which uses a model to pull options for the second dropdown from a DB. When I SAVE a DB record to reflect the chosen options it saves the "value" of the <option> tag. When I LOAD that record I get the value back, but I actually need the NAME, not the value. So, I'm trying to include a translator that will catch the data at the controller as it comes from the model to the view, translate the value into the name and then include the name in the object being passed to the view. What I need to do is access one specific element of the object. I'd rather not create an array, parse the object into the array, and then use the array element to pass back into the model to retrieve the name. Controller: Code: function loadRMA(){ //Function to load the RMA data from the DB Code: public function translateDropDown($type, $id){ //Function to translate the dropdown saved index value to its name value Any thoughts and/or suggestions?
Once you get the posted value, how do you save it if you don't know the name of the dropdown element in your form?
The selected value in a dropdown belongs to the name of the <select> ... </select> stucture. This part needs some more explanation, please also share the code of your view. Besides that, your function translateDropDown can be a lot shorter: PHP Code: public function translateDropDown($type, $id){
(03-18-2016, 06:27 AM)Wouter60 Wrote: Once you get the posted value, how do you save it if you don't know the name of the dropdown element in your form? Thanks for the reply Wouter60. I like your code reduction, I implemented it the way I did as there is a looming potential that the dropdown elements won't all be contained in one table, but given that, and your advice, I think I can use your reduction with a slight alteration. Much appreciated. As to the main issue. I probably did a poor job of communicating my issue/request. I know the name of the <select> element, but I'm looking to translate the option text. <option value="1">THIS TEXT</option>. The option value "1" is saved in the DB, so when I recall this I get "1" back, but need to translate that into the appropriate "THIS TEXT" for display (in a html table, not in a dropdown). Relevent View Code: Code: <select name="componentDropDown" onchange="selectSymptom(this.options[this.selectedIndex].value)"> Controller Code to Save DD Values back to DB: Code: function saveMode(){ |
Welcome Guest, Not a member yet? Register Sign In |