Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 5 of 5
  1. #1
    Regular Coder
    Join Date
    Jun 2007
    Location
    Los Angeles
    Posts
    545
    Thanks
    81
    Thanked 5 Times in 5 Posts

    Picking up form .value help

    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?
    RalphF
    Business Text Messaging Services
    https://www.MobileTextingService.com

  • #2
    Supreme Master coder! _Aerospace_Eng_'s Avatar
    Join Date
    Dec 2004
    Location
    In a place far, far away...
    Posts
    19,291
    Thanks
    2
    Thanked 1,043 Times in 1,019 Posts
    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
    Code:
    print $_POST['frm_image_name']."<br>";
    If you aren't using method="post" on your form then you can use $_GET instead.
    ||||If you are getting paid to do a job, don't ask for help on it!||||

  • #3
    Regular Coder
    Join Date
    Jun 2007
    Location
    Los Angeles
    Posts
    545
    Thanks
    81
    Thanked 5 Times in 5 Posts
    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>
    RalphF
    Business Text Messaging Services
    https://www.MobileTextingService.com

  • #4
    Regular Coder
    Join Date
    Jun 2007
    Location
    Los Angeles
    Posts
    545
    Thanks
    81
    Thanked 5 Times in 5 Posts
    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.
    RalphF
    Business Text Messaging Services
    https://www.MobileTextingService.com

  • #5
    Regular Coder
    Join Date
    Jun 2007
    Location
    Los Angeles
    Posts
    545
    Thanks
    81
    Thanked 5 Times in 5 Posts
    @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...
    RalphF
    Business Text Messaging Services
    https://www.MobileTextingService.com


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •