I'm looking for a way to add custom options to a drop-down selection list with Jquery. Then the user will click on the drop down, and will be presented with a list of options, being the last 'Add another ...' once they click it, they have their own choice (a pop up, Popovar, directly inline or else.)
In the post given below it says, however, that I am using CI which has options in the form of an array etc. I how it is implemented in code ignition Can i do
Thank you!
ps My JS knowledge is not great.
Try it for size:
< Strong> HTML :
& lt; Select ID = "myselect" & gt; & Lt; Option & gt; Hello & lt; / Options & gt; & Lt; Option & gt; World & lt; / Options & gt; & Lt; Option & gt; Add another ... & lt; / Options & gt; & Lt; / Select & gt; & Lt; Div id = "addother" & gt; & Lt; Input type = "text" id = "addother_input" /> & Lt; / Div & gt;
CSS :
#addother {display: none; }
JS :
$ (document) .ready (function () {$ ('# myselect'). Change (function (e) {if ($ (this) .val () == "Add another ...") {$ ('# addother'). Show (); // Set input back to empty string $ ('#edther_input'). Val ('');} and {$ ('# edether'). Hide ();}});});
edit : Sorry, about selecting a CI-generated element about erasing your line about this. In the CI, you select an element like this:
$ options = array ('small' = & gt; 'short shirt', 'med' => 'medium shirt', ' Big '= & gt; big shirt', 'excel' = & gt; extra large shirt ',); Model echo form_dropdown ('shirt', $ option);
If you want to make an additional choice, just try to end it:
$ options = array ('small' = & Gt ; 'Short shirt', 'Made' => 'Medium shirt', 'Big' = 'Big shirt', 'excel' = & gt; Additional large shirt, 'Idea' => Add another ... "); Echo form_dropdown ('shirt', $ option, tap, 'id = "myselect"'); Then, in your jQuery, test for "add other ..." for $ (this) .value () = $ "addother".
Comments
Post a Comment