CodeIgniter Forums
How to check form_dropdown() with javascript? - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forum-20.html)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forum-23.html)
+--- Thread: How to check form_dropdown() with javascript? (/thread-20105.html)



How to check form_dropdown() with javascript? - El Forum - 06-28-2009

[eluser]PEN Vannak[/eluser]
Dear CodeIgnitor members,

I want to add the javascript to check the form_dropdown().

Could you help me?

Best regards.


How to check form_dropdown() with javascript? - El Forum - 06-28-2009

[eluser]Thorpe Obazee[/eluser]
I might not understand what you mean here but if you intent to add some extra text in the form dropdown, you can some extra 'text' in the fourth parameter of the form_dropdown helper.


How to check form_dropdown() with javascript? - El Forum - 06-28-2009

[eluser]PEN Vannak[/eluser]
How can I add the fourth parameter to the form_dropdown?

I just want to add function called "onchange" to check the form_dropdown().
Lets see my code:
Code:
$data=array('mem_name'=>'Member','use_name'=>'Employee','boo_title'=>'Book','date_borrow'=>'Date Borrowed');
    $onchange=array('onClick'=>'[removed]search_by_date();');
    echo form_dropdown('search_by',$data,$onchange);
Does it is right or wrong?
With this case, it still doesn't work.
How can I change this code?

Best regards.


How to check form_dropdown() with javascript? - El Forum - 06-28-2009

[eluser]Thorpe Obazee[/eluser]
[quote author="PEN Vannak" date="1246262984"]How can I add the fourth parameter to the form_dropdown?

I just want to add function called "onchange" to check the form_dropdown().
Lets see my code:
Code:
$data=array('mem_name'=>'Member','use_name'=>'Employee','boo_title'=>'Book','date_borrow'=>'Date Borrowed');
    $onchange=array('onClick'=>'[removed]search_by_date();');
    echo form_dropdown('search_by',$data,$onchange);
Does it is right or wrong?
With this case, it still doesn't work.
How can I change this code?

Best regards.[/quote]

your form_dropdown function is still using 3 parameters.

Code:
echo form_dropdown('search_by',$data,$onchange, 'onChange="thisshouldwork()"');



How to check form_dropdown() with javascript? - El Forum - 06-28-2009

[eluser]ggoforth[/eluser]
There are various ways of doing it. I use jquery so I will show you that way, and also how to do it with basic javascript.

Basic

Code:
//select the element by it's id
var my_dropdown_val = docuement.getElementById('my_dropdown').value();
//do something with the value of the dropdown
alert(my_dropdown_val);

Next is how you could do it with jquery:

Code:
var my_dropdown_val = $('#my_dropdown').val();
alert(my_dropdown_val);

Just throw these in a function that you can call on change of the dropdown, with jquery it would look like:

Code:
$(docuement).ready(function(){
    $('#my_dropdown').change(function(){
         alert($(this).val());
    });
});

That is a few different ways you could do it. I would highly recommend looking into a javascript frame work like jquery. It will make your life a lot easier.

Greg