i want to dynamically render select options in a form, the number of the select tags that are rendered will depend on how many a user has selected..
for example, if a user says they want 3 items. i want to display 3 select options tags. Each of the input tags will have their values fed to them from an array function(its just a simple php array).
i am not sure of the best way to dynamically render these tags and would really appreciate some advice.
it might help if i show u what i mean.
the array values to be fed to the select tag:
the select tagPHP Code:$arrayValues = arrayValues()
{ return $selection = array( '0' => 'none' ,' 1' => '1 item' ,' 2' => '2 item' ,' 3' =>' 3 item' ); }
the code to determine how many tags a user wants;PHP Code:<select id="howmany" name="items[howmany]" />';
foreach ($arrayValues as $key => $value)
{
echo '<option value="' . $key .'">' . $value . '</option>';
}
echo'</select>';
i know how to dynamically render an input tags for a simple input tag. i.eCode:$(".howmany").change(function(){ var value = $(this).val(); }
Code:$('button').click(function () { $('div').empty().append(new Array(+$('input[type=number]').val()+1) .join("<input type='text' placeholder='Type Something'/>")); });
the issue for me is that my select tags has values fed to it from the $arrayValues.
thank you in advance for your kind assistance



Reply With Quote
Bookmarks