Welcome Guest, Not a member yet? Register   Sign In
Passing values from dropdown to an array as one
#1

[eluser]Michal1[/eluser]
Hey guys,

I am trying do a thing which will pass the values from 3 dropdowns to a one array. The reason why I am doing this is that.

I have three dropdowns. First one contains numbers from 1-31 second one has 1-12 and the third one has 2009,2010,2011

Most of you now probably realised that those are like a date dropdowns.

Now I have an array data and I want to insert into that selected values from all three dropdowns. Is that possible? Or do I need to create 3 fields in an array for each dropdown and have something like this

Code:
$data=array(
'day'=>$this->input->post('day_dropdown'),
'month'=>$this->input->post('month_dropdown'),
'year'=>$this->input->post('year_dropdown')
);

I would rather have something like this

code]$data=array(
'date'=>$this->input->post(alldropdown values..or something like that)
);
[/code]

Or is there any better view hot to handle dropdowns with date?

Thank you
#2

[eluser]Derek Allard[/eluser]
Code:
<select name="selection_date[days]">...days...</select>
<select name="selection_date[months]">...months...</select>
<select name="selection_date[years]">...years...</select>

Still thoguh, if it were me, and I was building 3 dropdowns, then I'd probably want to harvest them when they are submitted as 3 separate form fields.

edit: removed quotes, thanks noctrum!
#3

[eluser]Michal1[/eluser]
Ok thank you. And is there any better way how to work with date dropdown?

I just basically want to have a dropdown where user can choose a day, month and year and then I would like to pass that date which he elected as a one to some array for example?
#4

[eluser]danmontgomery[/eluser]
jQuery datepicker, generally.

Just a small correction to Derek's post, HTML arrays don't use quotes:

Code:
<select name="selection_date[day]">...</select>
<select name="selection_date[month]">...</select>
<select name="selection_date[year]">...</select>

This gives you what you're asking for, all 3 values in one array. If you have 3 dropdowns, you're going to have 3 values.
#5

[eluser]Michal1[/eluser]
Thank you, so I am trying to use a jquery date picker. It seems great however I have a problem with passing data from it to array. I have this in my view

Code:
[removed]
    $(function() {
        $( "#to_them" ).datepicker();
    });
    [removed]



<div class="demo">

<p> &lt;input id="to_them" type="text"&gt;&lt;/p>

</div>&lt;!-- End demo --&gt;

and id one of my controller functions I have

Code:
$data = array(
            
            'from_them'=>$this->input->post('from_them')
                );


However it always receives an 0. Why is that? Thx
#6

[eluser]danmontgomery[/eluser]
I don't see any form, but input values are passed via the 'name' attribute

Code:
&lt;input type="text" name="from_them" id="from_them"/&gt;




Theme © iAndrew 2016 - Forum software by © MyBB