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


No announcement yet.

3 Forms - Variable needed without entering twice

  • 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
      <script language="Javascript">
    		  var refer = document.referform.referral.value;
    		  document.write('<input type=\"hidden\" name=\"referral\" value=\"' + refer + '\">');
    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.


  • #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.


    • #3

      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


      • #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">
        vBulletin Mods That Rock!


        • #5
          You Star!!!


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



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