Automatically input ref. no. into contact form input box on clicking a button

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • tamjames75
    New Member
    • Mar 2008
    • 3

    Automatically input ref. no. into contact form input box on clicking a button

    Hi there,

    I'm new to javascript and am looking for a solution to my problem, I am creating a site for a property company and they want a enquire button next to each property and when clicked it goes to the contact form I have created where it automatically inputs the property ref number in the ref no. input box.

    Can anyone please help me on the code for this?

    Cheers TJ.
  • gits
    Recognized Expert Moderator Expert
    • May 2007
    • 5388

    #2
    could you tell whether the contact form opens in a popup or replaces the current page? could you post an example code?

    kind regards

    Comment

    • tamjames75
      New Member
      • Mar 2008
      • 3

      #3
      The form replaces the current window, I haven't attached any properties yet but have created the form at this address:

      http://properties.barg afinance.co.uk/contact/

      TJ

      Comment

      • gits
        Recognized Expert Moderator Expert
        • May 2007
        • 5388

        #4
        so you could pass it with a query-string:

        Code:
        http://properties.bargafinance.co.uk/contact/form.html?ref_id=123456
        now in your form you could retrieve this with:

        [CODE=javascript]var query_string = window.location .search;[/CODE]
        kind regards

        Comment

        • tamjames75
          New Member
          • Mar 2008
          • 3

          #5
          Thanks for your help, but how could I get that to appear in the input box what code would I need to put on that?

          I have entered my link as in what you said but on the form how does it know to appear in that input box?

          Cheers.

          Comment

          • gits
            Recognized Expert Moderator Expert
            • May 2007
            • 5388

            #6
            use the onload of your formpage to call a function like the following:

            [CODE=javascript]function get_ref_id() {
            var qs = window.location .search;
            var ref_id = qs.match(/([^=]+$)/)[1];
            var node = document.getEle mentById('your_ element_id');

            node.value = ref_id;
            }
            [/CODE]
            kind regards

            Comment

            • acoder
              Recognized Expert MVP
              • Nov 2006
              • 16032

              #7
              Changed the thread title. Please remember to Use a Good Thread Title. Thanks!

              Comment

              Working...