View Full Version : Picking up form .value help

01-13-2008, 12:18 AM
I have the following JS code in my main.php form:

function image_name()
document.task_form.frm_image_name.value = "1234";
I have the frm_image_name in my main form as hidden:

<INPUT NAME="frm_image_name" TYPE="hidden">

When the form is called, my php line:

print $frm_image_name."<br>";

does not print '1234' - I *thought* I could pass a string in JS to PHP this way once the form was called?

Am I missing something here?

01-13-2008, 12:56 AM
You could do that only if register_globals was set to on. For security reasons you don't want them set to on. Instead you should do this

print $_POST['frm_image_name']."<br>";
If you aren't using method="post" on your form then you can use $_GET instead.

01-13-2008, 01:54 AM
Yes, you are correct, however, in my case that doesn't work. I was trying to simplify my code. My main form code below displays a link with a photo name - if I have only one link (the code below executes once) then your solution works fine. However, if I have two of these links then your print statment prints a blank. It has something to do with using this code below more than once on the main form but I don't know what the trick is to making it work for multiple links. I'm trying to pass the photo filename to my called php form using that hidden input .value.

<A HREF='javascript:image_name("<?php echo $php_photo_name?>")'>[confirm name]</A>

01-13-2008, 02:37 AM
I added the multiple select brackets in the hidden input object:

<INPUT NAME="frm_image_name[]" TYPE="hidden">

and using a for loop I was able to loop thru the input tag values OK - however, I could not tell which link I clicked on, meaning, I could not detect which photo filename I actually clicked on. The for loop always displays the photo filenames correctly to match with the links, but I can determine which link I clicked on.

01-13-2008, 04:38 PM

Your solution was correct. I had my hidden input statement inside my SQL loop and when I put it outside of this loop it worked fine.


EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum