Results 1 to 5 of 5

Thread: Get form value

  1. #1
    Join Date
    Dec 2004
    Posts
    28

    Unanswered: Get form value

    Hi is it possible to get a value from a text field that isn't associated with no button with PHP using something like javascripts document.myform.text.value?

    I tried to create a javascript function that would do this and then pass the value to a session variable. The problem I get is that I can't trigger the function with the button.

    The button that should trigger the function is embedded in PHP and only appear after a certain paramater is met.

    I hope I explained myself, thanks for any sugestions

    chears

  2. #2
    Join Date
    Nov 2004
    Location
    out on a limb
    Posts
    13,692
    Provided Answers: 59
    the problem is that PHP runs on the server.. so it hasnt got a scooby whats happening at the client untill the client informs the server of what it wants to do next. So its either set a value at the server that will happen when the user triggers an event, or use Javascript to do what you want and send the value back to the server,

    if you are using a form then use a hidden variable, otherwise you may need to "hardcode" the value as part of the writing of the PHP page eg <http://mysite/mypage.php?myvalue>

    failing that youi may need to do a Javascript call using somehting like AJAX, or if thats to over the top use a javascript function to interpret what the correct URL should be.

    failing that use session variables if approporiate
    I'd rather be riding on the Tiger 800 or the Norton

  3. #3
    Join Date
    Dec 2004
    Posts
    28
    Hi Healdem,
    thank you for your reply.

    I managed to get the values with javascript, how can I pass the value to a PHP variable? I mean something like this <?PHP $somevar=?> <script>document.myform.mytext.value</script>
    unfortunely this didn't work but is there a walk around.

    cheers

  4. #4
    Join Date
    Nov 2004
    Location
    out on a limb
    Posts
    13,692
    Provided Answers: 59
    if you are using the variable in another form then the normal URL is
    http://<mysite>.<mypage>?<myvalue1>=<value1>....

    or if you are using a form to capture the user interaction then use a control such as a text box or radio. You can if you wish use a hidden control if its a value that isnt going to be changed by the user.

    if its a form in the script that is the action of the form tag then you can pick up the value of any control by looking at the $GET_ collection. I wouldn't use import_request_variables (for security reasons) but instead $_GET['<my controlname>']
    I'd rather be riding on the Tiger 800 or the Norton

  5. #5
    Join Date
    Dec 2004
    Posts
    28
    Hi still didn't manage to get it working.

    What is the javascript equivalent to PHP hearder ("location: some_url.php");

    window.open() doesn't work how I want, and if I use the document.write(<a href="something.php">) doesn't work. What am I doing wrong?

    Btw how can I use a custom button to submit a form. I think if I managed this I could solve the entire problem.

    Thanks for any help

Posting Permissions

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