on select change load value |
[eluser]il_dandi[/eluser]
Hi! In my view I've 2 fields <tr> <td align="right">commessa: </td> <td> <select name="idCommessa" id="idCommessa"> <option value=""></option> <? foreach ($commesse->result() as $row):?> <option value="<?=$row->id?>"<? if($idCommessa==$row->id) echo " selected" ?>><?=$row->titolo?></option> <? endforeach?> </select> </td> </tr> <tr> <td align="right">oggetto: </td> <td><input name="oggetto" type="text" id="oggetto" size="40" maxlength="255" value="<?=$oggetto?>"></td> </tr> I would like to automatically load a value in "oggetto" input when I change the selected items in select field: when I select a value in "idCommessa" I've to show in "oggetto" field the value: $row->titolo of commessa Thanks
[eluser]Georgi Budinov[/eluser]
Hello You have to attach a function on the onchange event of the select element onchange="onChangeSelection();" If you use JQuery define the onChangeSelection function like this: Code: function onChangeSelection(){ If you do not use any js library use this: Code: function onChangeSelection(){ Hope it is helpfull. Though I haven't tested it, but should be ok.
[eluser]il_dandi[/eluser]
Thanks for your reply!! I've do this: <select name="idCommessa" id="idCommessa"> <option value=""></option> <? foreach ($commesse->result() as $row):?> <option value="<?=$row->id?>"<? if($idCommessa==$row->id) echo " selected" ?>><?=$row->titolo?></option> <? endforeach?> </select> and in the same page (in my view) I've: <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> <title>aaaa</title> [removed][removed] [removed] function onChangeSelection(){ $('#oggetto').val($('#idCommessa optionelected').text()); } [removed] </head> but it doesn't works.... where is it my error? Thanks
[eluser]Georgi Budinov[/eluser]
This is a fast working example: Code: <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
[eluser]il_dandi[/eluser]
I've included this js [removed][removed] it's OK? I still have the same problem
[eluser]danmontgomery[/eluser]
If you're using jquery, why not go all the way? Code: <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
[eluser]Georgi Budinov[/eluser]
Yes you could do that too. I wrote my post as fast reply, but however generally I am trying not to use the onload event for processing stuff like that, when possible of course.
[eluser]il_dandi[/eluser]
Now it works!! with $(function() { can you tell me the differences between your first solution? thanks
[eluser]il_dandi[/eluser]
Now that I've resolved this, I've also this prolem: http://ellislab.com/forums/viewthread/159054/ I think that it's similar but I don't know how to resolve it Thanks |
Welcome Guest, Not a member yet? Register Sign In |