Web Analytics Made Easy -
StatCounter 3 Forms - Variable needed without entering twice - CodingForum

Announcement

Collapse
No announcement yet.

3 Forms - Variable needed without entering twice

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • 3 Forms - Variable needed without entering twice

    Let me explain,

    I have 3 forms on one page. One is to collect the details of any referral details and the other 2 are for payment (paypal or cheque)

    My thinking is that Javascript should be able to pull the details as they are on the same page.
    This is what I've got so far
    Code:
      <script language="Javascript">
    		  <!-- 
    		  var refer = document.referform.referral.value;
    		  document.write('<input type=\"hidden\" name=\"referral\" value=\"' + refer + '\">');
    
    		  //-->
    </script>
    This code is placed in the payment forms to passed over with payment, but its always empty - no matter what is typed in.

    Any help appreciated.

    Cheers

  • #2
    I'd say from the look of what you posted that the document.write in your script is being written to the form as your page is being loaded in the first place so unless that field is coming with a value pre-filled into it from your server...


    You need to fill the value into this form from the other form at the time the form is submitted to get whatever value was entered. Of course you could also consider moving the form field to the the form it'll be submitted with instead (assuming that the form it's already in is never submitted, otherwise forget that idea).
    Check out the Forum Search. It's the short path to getting great results from this forum.

    Comment


    • #3
      eh?

      Either because I'm half asleep or whatever, but I didn't understand a word of that!!

      Check the file for the source code - maybe I didn't explain what I wanted to do fully before
      Attached Files

      Comment


      • #4
        The script you posted will only be executed as the page loads not after the page has loaded. And the "referral" field has no default value, that's why the hidden field also has no value. If you want the hidden field to have the value as the user types in the "referral" field, you need to attach an onchange handler to the field that will change the value of the hidden field

        <input type="text" name="referral" class="form" onchange="document.forms.cash.referral.value=this.value">
        Glenn
        vBulletin Mods That Rock!

        Comment


        • #5
          You Star!!!

          Superb,

          Thanks very much - hopefully I'll be able to repay the favour soon!

          Mark

          Comment


          • #6
            You're welcome.
            Glenn
            vBulletin Mods That Rock!

            Comment

            Working...
            X