Simple question! Using text box value in a Ahref!

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Adrian

    Simple question! Using text box value in a Ahref!

    hi,
    if i have a textbox (not in a form) on an html page and a link to
    another page how can I use the textbox value when the link is clicked?

    i.e.
    <input type="text" name="T1" size="20">
    <a href="abc" & t1.value>test link</a>

    so if the textbox value was "def" the link when clicked would be abcdef



  • Randy Webb

    #2
    Re: Simple question! Using text box value in a Ahref!

    Adrian said the following on 1/8/2006 12:28 PM:[color=blue]
    > hi,
    > if i have a textbox (not in a form) on an html page[/color]

    A textbox not in a form? Odd.
    Give your textbox a proper form. Or, an ID.
    [color=blue]
    > and a link to another page how can I use the textbox value when the link is clicked?
    > i.e.
    > <input type="text" name="T1" size="20">
    > <a href="abc" & t1.value>test link</a>
    >
    > so if the textbox value was "def" the link when clicked would be abcdef[/color]

    <a href="abc"
    onclick="this.h ref=this.href+d ocument.getElem entById('T1').v alue)">
    Test Link</a>

    Assuming you give it an ID of T1 also.

    --
    Randy
    comp.lang.javas cript FAQ - http://jibbering.com/faq & newsgroup weekly
    Javascript Best Practices - http://www.JavascriptToolbox.com/bestpractices/

    Comment

    • Janwillem Borleffs

      #3
      Re: Simple question! Using text box value in a Ahref!

      Adrian wrote:[color=blue]
      > if i have a textbox (not in a form) on an html page and a link to
      > another page how can I use the textbox value when the link is clicked?
      >
      > i.e.
      > <input type="text" name="T1" size="20">
      > <a href="abc" & t1.value>test link</a>
      >
      > so if the textbox value was "def" the link when clicked would be
      > abcdef[/color]

      <a href="abc"
      onclick="this.h ref += document.forms[0].elements['T1'].value; return
      true">
      test link</a>


      JW


      Comment

      • David Dorward

        #4
        Re: Simple question! Using text box value in a Ahref!

        Adrian wrote:
        [color=blue]
        > if i have a textbox (not in a form) on an html page and a link to
        > another page how can I use the textbox value when the link is clicked?[/color]

        Put the text box in a form. Replace the link with a submit button. Style the
        form to make it display inline. Style the submit button to make it look
        like a link.

        .... then it won't break if JavaScript isn't available or is turned off on
        the client.

        --
        David Dorward <http://blog.dorward.me .uk/> <http://dorward.me.uk/>
        Home is where the ~/.bashrc is

        Comment

        • Randy Webb

          #5
          Re: Simple question! Using text box value in a Ahref!

          Janwillem Borleffs said the following on 1/8/2006 12:36 PM:[color=blue]
          > Adrian wrote:
          >[color=green]
          >> if i have a textbox (not in a form) on an html page and a link to
          >>another page how can I use the textbox value when the link is clicked?
          >>
          >>i.e.
          >><input type="text" name="T1" size="20">
          >><a href="abc" & t1.value>test link</a>
          >>
          >>so if the textbox value was "def" the link when clicked would be
          >>abcdef[/color]
          >
          >
          > <a href="abc"
          > onclick="this.h ref += document.forms[0].elements['T1'].value; return
          > true">
          > test link</a>[/color]

          IE6:

          document.forms. 0.elements is null or not an object.

          Mozilla:

          Error: document.forms[0] has no properties

          --
          Randy
          comp.lang.javas cript FAQ - http://jibbering.com/faq & newsgroup weekly
          Javascript Best Practices - http://www.JavascriptToolbox.com/bestpractices/

          Comment

          • Adrian

            #6
            Re: Simple question! Using text box value in a Ahref!

            Thank you all for your help.


            "Adrian" <Adrian@nospamh otmail.com.uk> wrote in message
            news:dpri48$6q5 $1@nwrdmz02.dmz .ncs.ea.ibs-infra.bt.com...[color=blue]
            > hi,
            > if i have a textbox (not in a form) on an html page and a link to
            > another page how can I use the textbox value when the link is clicked?
            >
            > i.e.
            > <input type="text" name="T1" size="20">
            > <a href="abc" & t1.value>test link</a>
            >
            > so if the textbox value was "def" the link when clicked would be abcdef
            >
            >
            >[/color]


            Comment

            • Jasen Betts

              #7
              Re: Simple question! Using text box value in a Ahref!

              On 2006-01-08, Adrian <Adrian@nospamh otmail.com.uk> wrote:[color=blue]
              > hi,
              > if i have a textbox (not in a form) on an html page and a link to
              > another page how can I use the textbox value when the link is clicked?
              >
              > i.e.[/color]

              [color=blue]
              ><input type="text" name="T1" size="20">
              ><a href="abc" & t1.value>test link</a>[/color]

              [color=blue]
              > so if the textbox value was "def" the link when clicked would be abcdef[/color]


              <input type="text" id="T1" size="20">
              <a
              href="abc"
              onclick="this.h ref+=document.g etElementById(' T1').value"[color=blue]
              >[/color]
              test link</a>

              should work on most recent browsers if javascript is enabled, else they'll
              get "abc" as the link.


              Bye.
              Jasen

              Comment

              Working...