Welcome Guest, Not a member yet? Register   Sign In
How to check form_dropdown() with javascript?
#1

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

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

Could you help me?

Best regards.
#2

[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.
#3

[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.
#4

[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()"');
#5

[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




Theme © iAndrew 2016 - Forum software by © MyBB