...

View Full Version : Picking up form .value help



rfresh
01-12-2008, 11:18 PM
I have the following JS code in my main.php form:

function image_name()
{
document.task_form.frm_image_name.value = "1234";
document.task_form.submit();
}
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?

_Aerospace_Eng_
01-12-2008, 11:56 PM
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.

rfresh
01-13-2008, 12: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>

rfresh
01-13-2008, 01: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.

rfresh
01-13-2008, 03:38 PM
@aerospace

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.

Thanks...



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum