![]() |
Accessing hidden form fields - Printable Version +- CodeIgniter Forums (https://forum.codeigniter.com) +-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20) +--- Forum: Archived General Discussion (https://forum.codeigniter.com/forumdisplay.php?fid=21) +--- Thread: Accessing hidden form fields (/showthread.php?tid=17419) |
Accessing hidden form fields - El Forum - 04-04-2009 [eluser]halwaraj[/eluser] I have the hidden filed like this: Code: <input name="hiddenOne" value="" type="hidden"> Code: <button name="aButton" type="submit" id="aButton" value="false">Edit</button> The javascript function: Code: function clicked(){ Code: $FE[ 'titleStory' ] = $_POST[ 'hiddenOne' ]; But the following does not print anything Code: echo $FE[ 'titleStory' ]; What is happening? I am able to access the other form elements like "input". Accessing hidden form fields - El Forum - 04-04-2009 [eluser]oll[/eluser] Your clicked() function won't be called by magic just because its name is "clicked" ![]() Typically Code: <button name="aButton" type="submit" onclick#"clicked()" > Replace # by = in the aboveline : the forum doesn't seem to like it : it refuses me to write it. Accessing hidden form fields - El Forum - 04-05-2009 [eluser]halwaraj[/eluser] [quote author="oll" date="1238878344"]Your clicked() function won't be called by magic just because its name is "clicked" ![]() Typically Code: <button name="aButton" type="submit" onclick#"clicked()" > Replace # by = in the aboveline : the forum doesn't seem to like it : it refuses me to write it.[/quote] Oh, I had it in the code, just that forgot to put that here. Here is the missing part: Code: echo form_button( $button, '', $js ); the code Code: <button name="aButton" type="submit" id="aButton" value="false">Edit</button> is what is getting generated. I put an alert in the js function. It is working properly. What else do I need to look at? Accessing hidden form fields - El Forum - 04-05-2009 [eluser]halwaraj[/eluser] As oll said the board does not allow the event functions to be typed and thts how it missed in the first post. It is missing from my second post also. Not that I missed it. Accessing hidden form fields - El Forum - 04-05-2009 [eluser]oll[/eluser] ouch..yes, I should have guessed it after I realized the forum removed the onclick ![]() But I have no solution, so, sorry. It looks like a pure javascript problem and how events are managed within the DOM. Maybe the "submit" event is sent before the "onclick" one when you click (so making the clicked() function never be executed ). You might test creating a fake element (a fake <a> for instance), put the onclick=yourfuntion() in it, and test if it works when you click on your fake <a> and then click on submit. You might also try removing your submit tag , and put the submit event at the end of you js function. But this will make your js be obstructive (ie it won't work anymore if the user disables js) Accessing hidden form fields - El Forum - 04-05-2009 [eluser]CroNiX[/eluser] Its been awhile since I played with js outside of a good framework, so this might not be right. I believe "getElementsByName" returns an array of elements so you might not be accessing it properly since you are trying to only get 1 element. It might work better if you assign unique id's to your hidden form elements and use "getElementById" instead so you are only selecting 1 element. I would also get firebug if you aren't using it already as it makes this kind of thing a lot easier to debug/test. Accessing hidden form fields - El Forum - 04-05-2009 [eluser]halwaraj[/eluser] I resolved it. CroNiX is right. “getElementsByName” returns a array of element and I changed Code: document.getElementsByName('hiddenOne').value='Lauda'; Code: document.getElementsByName('hiddenOne')[0].value='Lauda'; |