Welcome Guest, Not a member yet? Register   Sign In
Accessing hidden form fields
#1

[eluser]halwaraj[/eluser]
I have the hidden filed like this:
Code:
<input name="hiddenOne" value="" type="hidden">
<input name="hiddenTwo" value="" type="hidden">
A Button like this:
Code:
<button name="aButton" type="submit" id="aButton" value="false">Edit</button>

The javascript function:
Code:
function clicked(){
            document.getElementsByName('hiddenOne').value='Lauda';
            document.getElementsByName('hiddenTwo').value='chut ka dhakkan';
            document.EditStoryForm.submit();
        }
On the server side (PHP) I am trying to do the following:
Code:
$FE[ 'titleStory' ] = $_POST[ 'hiddenOne' ];
        $FE[ 'actualStory' ] = $_POST[ 'hiddenTwo' ];

But the following does not print anything
Code:
echo $FE[ 'titleStory' ];
echo $FE[ 'actualStory' ];

What is happening?

I am able to access the other form elements like "input".
#2

[eluser]oll[/eluser]
Your clicked() function won't be called by magic just because its name is "clicked" Wink. You have to put an event somewhere.
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.
#3

[eluser]halwaraj[/eluser]
[quote author="oll" date="1238878344"]Your clicked() function won't be called by magic just because its name is "clicked" Wink. You have to put an event somewhere.
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 );

$js = 'onclick="return clicked()"';


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?
#4

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

[eluser]oll[/eluser]
ouch..yes, I should have guessed it after I realized the forum removed the onclick Wink

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)
#6

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

[eluser]halwaraj[/eluser]
I resolved it. CroNiX is right. “getElementsByName” returns a array of element and I changed
Code:
document.getElementsByName('hiddenOne').value='Lauda';
to this
Code:
document.getElementsByName('hiddenOne')[0].value='Lauda';
and it works butter.




Theme © iAndrew 2016 - Forum software by © MyBB