Welcome Guest, Not a member yet? Register   Sign In
How do I add onChange event to input using form_helper?
#1

[eluser]Sven Delle[/eluser]
I'd like to add a javascript onChange function to an input field.

I've tried this:

Code:
$title_params = array('id' => 'title', 'name' => 'title', 'value' => $title, 'onChange' => 'java/script:do_stuff();');
echo form_input($title_params);

and (passing as second paramter):
Code:
$title_params = array('id' => 'title', 'name' => 'title', 'value' => $title);
$title_js = 'onChange=java/script:do_stuff()';
echo form_input($title_params, $title_js);

Even tried as third parameter, as it says you can do with a button in the docs. No luck.

How would I go about doing this with the form_helper?
#2

[eluser]FightingMan[/eluser]
Good luck with you! I am not good at js, sorry
#3

[eluser]Sven Delle[/eluser]
Thanks : ) scary that luck is needed, huh?

I did this - totally ignoring the form_helper:

Code:
echo '<input type="text" id="title" name="title" value="Title" onkeydow/n="javascrip/t:update_slug();" />';
#4

[eluser]Stefan Hueg[/eluser]
As taken directly from the CI documentation:

Code:
$js = 'onClick="some_function()"';
echo form_input('username', 'johndoe', $js);

There you go.

You may have forgotten the double quotes.
#5

[eluser]Sven Delle[/eluser]
Managed to do it this way:

Code:
$title_params = array('id' => 'title', 'name' => 'title', 'value' => $title, 'onkeydown' => 'javascrip_t:update_slug();', 'onblur' => 'javascrip_t:update_slug();');
echo form_input($title_params);

If that may help someone else.
#6

[eluser]CroNiX[/eluser]
It's better not to have inline javascript, anyway Smile
#7

[eluser]Sven Delle[/eluser]
Yeah, but it's the only way I see if you want to 'beef' up the interface. And placing the code in a separate js file I won't be able to load it along with the view through AJAX. Or at least I don't have the time due to deadlines to try and figure out how to do this.

Most of the time it's about getting things done. Unfortunately. Otherwise we could all make GREAT solutions.




Theme © iAndrew 2016 - Forum software by © MyBB