CodeIgniter Forums

Full Version: form_dropdown and javascript
You're currently viewing a stripped down version of our content. View the full version with proper formatting.

El Forum

[eluser]filip_de_backer[/eluser]
hi everyone,

I've got the following code:
// $clubs is an array
echo form_dropdown('ddlClubs', $clubs);

when I want to het the selected value with javascript I have an error (object is null)

var e = document.getElementById("ddlClubs");

When I change the form_dropdown to the html <input> tag, it works fine.

What have I forgotten in the code?

The form_dropdown is server code and the javascript is client code so normally the dropdown should be accessible.

thanks

Filip

El Forum

[eluser]Kamarg[/eluser]
The first parameter sets the name of the dropdown not the id.

Code:
echo form_dropdown('ddlClubs', $clubs, 0, 'id="ddlClubs"');

El Forum

[eluser]filip_de_backer[/eluser]
thanks! problem solved!