append textbox value to href link before submit

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

    append textbox value to href link before submit

    Hi

    I have a page with a form and a textbox.
    before to submit the form I want to chek if the inserted value in the
    textbox is already present in a database.
    So I need to pass the textbox value by a javascript link to another
    page to check.
    my code is
    <a href="javascrip t:location.href ='page_check.ph p' "Go check </a>
    and this work and open page_check.php

    but when I want to append the textbox value, the code not work. I know
    I make mistake

    <a href="javascrip t:location.href ='page_check.ph p?Box=' +
    document.formNa me.textboxName. value "Go check </a>

    Any suggest ?
    Regards
  • sheldonlg

    #2
    Re: append textbox value to href link before submit

    pt36 wrote:
    Hi
    >
    I have a page with a form and a textbox.
    before to submit the form I want to chek if the inserted value in the
    textbox is already present in a database.
    So I need to pass the textbox value by a javascript link to another
    page to check.
    my code is
    <a href="javascrip t:location.href ='page_check.ph p' "Go check </a>
    and this work and open page_check.php
    >
    but when I want to append the textbox value, the code not work. I know
    I make mistake
    >
    <a href="javascrip t:location.href ='page_check.ph p?Box=' +
    document.formNa me.textboxName. value "Go check </a>
    >
    Any suggest ?
    Regards
    Since checking of a database is done on the server, it seems to me that
    what you want is AJAX. Have an "onclick=foo()" . In foo you would make
    the AJAX call and return a message to the browser depending upon whether
    there is no match or is a match. If this is for checking before
    submitting the page, then get rid of the check button, keep the action
    as the where you want the page submitted to, put a "return foo()" in the
    form definition, and return either false or true from foo.

    What do you mean by it doesn't work? Does the php file not see the
    value? Does the php file see the value, but you don't get values back
    to the current page? What happens?

    Comment

    • Doug Gunnoe

      #3
      Re: append textbox value to href link before submit

      On Jul 7, 9:03 pm, pt36 <key.albe...@gm ail.comwrote:
      Hi
      >
      I have a page with a form and a textbox.
      before to submit the form I want to chek if the inserted value in the
      textbox is already present in a database.
      So I need to pass the textbox value by a javascript link to another
      page to check.
      my code is
      <a href="javascrip t:location.href ='page_check.ph p' "Go check </a>
      and this work and open page_check.php
      >
      but when I want to append the textbox value, the code not work. I know
      I make mistake
      >
      <a href="javascrip t:location.href ='page_check.ph p?Box=' +
      document.formNa me.textboxName. value "Go check </a>
      >
      Any suggest ?
      Regards
      this:

      <html>
      <head>
      <script>
      function changeURL(){
      var lnk = document.getEle mentById('somel ink');
      lnk.href = lnk.href + "?" + document.getEle mentById('txtbx ').value;
      }
      </script>
      </head>
      <body>
      <input type="text" value="" id="txtbx" />
      <a href="some_file .html" id="somelink">< input type="button"
      value="Check it" onmousedown="ch angeURL();" /></a>
      </body>
      </html>

      Or, I think this one is better:

      <html>
      <head>
      <script>
      function changeURL(){
      window.location = "some_file. php" + "?" +
      document.getEle mentById('txtbx ').value;
      }
      </script>
      </head>
      <body>
      <input type="text" value="" id="txtbx" />
      <input type="button" value="Check it" onmousedown="ch angeURL();" />
      </body>
      </html>

      Comment

      • Doug Gunnoe

        #4
        Re: append textbox value to href link before submit

        On Jul 7, 9:03 pm, pt36 <key.albe...@gm ail.comwrote:
        Hi
        >
        I have a page with a form and a textbox.
        before to submit the form I want to chek if the inserted value in the
        textbox is already present in a database.
        So I need to pass the textbox value by a javascript link to another
        page to check.
        my code is
        <a href="javascrip t:location.href ='page_check.ph p' "Go check </a>
        and this work and open page_check.php
        >
        but when I want to append the textbox value, the code not work. I know
        I make mistake
        >
        <a href="javascrip t:location.href ='page_check.ph p?Box=' +
        document.formNa me.textboxName. value "Go check </a>
        >
        Any suggest ?
        Regards
        you can try this:

        <html>
        <head>
        <script>
        function changeURL(){
        var lnk = document.getEle mentById('somel ink');
        lnk.href = lnk.href + "?" + document.getEle mentById('txtbx ').value
        }
        </script>
        </head>
        <body>
        <input type="text" value="" id="txtbx" />
        <a href="some_file .php" id="somelink">< input type="button"
        value="Check it" onmousedown="ch angeURL();" /></a>
        </body>
        </html>

        or, I think this is better:

        <html>
        <head>
        <script>
        function changeURL(){
        window.location = "some_file. php" + "?" +
        document.getEle mentById('txtbx ').value;
        }
        </script>
        </head>
        <body>
        <input type="text" value="" id="txtbx" />
        <input type="button" value="Check it" onmousedown="ch angeURL();" />
        </body>
        </html>

        Comment

        • Thomas 'PointedEars' Lahn

          #5
          Re: append textbox value to href link before submit

          Doug Gunnoe wrote:
          Or, I think this one is better:
          Better in which regard?
          <html>
          <head>
          <script>
          function changeURL(){
          window.location = "some_file. php" + "?" +
          document.getEle mentById('txtbx ').value;
          }
          </script>
          </head>
          <body>
          <input type="text" value="" id="txtbx" />
          <input type="button" value="Check it" onmousedown="ch angeURL();" />
          </body>
          </html>
          This is but an invalid, inefficient, error-prone tag soup.


          PointedEars
          --
          realism: HTML 4.01 Strict
          evangelism: XHTML 1.0 Strict
          madness: XHTML 1.1 as application/xhtml+xml
          -- Bjoern Hoehrmann

          Comment

          • pt36

            #6
            Re: append textbox value to href link before submit

            On 8 Lug, 12:49, sheldonlg <sheldonlgwrote :
            pt36 wrote:
            Hi
            >
            I have a page with a form and a textbox.
            before to submit the form I want to chek if the inserted value in the
            textbox is already present in a database.
            So I need to pass the textbox value by a javascript link to another
            page to check.
            my code is
            <a href="javascrip t:location.href ='page_check.ph p' "Go check </a>
            and this work and open page_check.php
            >
            but when I want to append the textbox value, the code not work. I know
            I make mistake
            >
            <a href="javascrip t:location.href ='page_check.ph p?Box=' +
            document.formNa me.textboxName. value "Go check </a>
            >
            Any suggest ?
            Regards
            >
            Since checking of a database is done on the server, it seems to me that
            what you want is AJAX.  Have an "onclick=foo()" .  In foo you would make
            the AJAX call and return a message to the browser depending upon whether
            there is no match or is a match.  If this is for checking before
            submitting the page, then get rid of the check button, keep the action
            as the where you want the page submitted to, put a "return foo()" in the
            form definition, and return either false or true from foo.
            >
            What do you mean by it doesn't work?  Does the php file not see the
            value?  Does the php file see the value, but you don't get values back
            to the current page?  What happens?- Nascondi testo citato
            >
            - Mostra testo citato
            ok Well
            i have a page that submit a form. In the page, near to the textbox
            when a user insert his nik, I want that the user be alerted that the
            nik inserted in the textbox is already used, so have to choose
            another. I will that this happen before to submit the form.
            In php after submitting the page I am able to check this, and also I
            not need help for the php code for this.
            I am able to make this procedure and see the alert in a new windows
            popup.
            I will that the alert appear in the page, near the textbox, (in a DIV)
            If an Ajax procedure helps me i say thanks, please send suggestions.

            When I say "not work" I mean that the link was wrote not corrected and
            not work.
            if you write my code you see what happen
            In the first example the link open the page page_check.php
            In the second example the link not open the page_page.php and the link
            path is incorrect.

            eg. When a user try to register to yahoo, when you write your
            username, sometime you receive a warning that your username is not
            available. I want to do the same.
            Regards

            Comment

            • Thomas 'PointedEars' Lahn

              #7
              Re: append textbox value to href link before submit

              pt36 wrote:
              i have a page that submit a form. In the page, near to the textbox
              when a user insert his nik, I want that the user be alerted that the
              nik inserted in the textbox is already used, so have to choose
              another. I will that this happen before to submit the form.
              In php after submitting the page I am able to check this, and also I
              not need help for the php code for this.
              I am able to make this procedure and see the alert in a new windows
              popup.
              I will that the alert appear in the page, near the textbox, (in a DIV)
              Apparently you don't mean an alert message window. Note that `alert' has
              a somewhat fixed meaning when dicussion client-side scripting, denoting
              window.alert(). That may have caused confusion.
              If an Ajax procedure helps me i say thanks, please send suggestions.
              <http://developer.mozil la.org/en/docs/AJAXis a good starting point. You
              should also search the Google archives of this newsgroup, there are plenty
              of XHR examples in it (many of them posted by me).

              As for the form, here is a template for you to experiment with:

              <form action="..." onsubmit="retur n checkUser(this) ">
              <script type="text/javascript">
              function checkUser(f)
              {
              // use wrapper object with feature test here instead
              var x = new XMLHttpRequest( );

              // "synchronou s" request to request plain text (SJAT ;-))
              x.open("GET", "/check_user?user ="
              + encodeURICompon ent(f.elements["username"].value), false);
              x.send(null);
              if (x.status == 200 && x.responseText == "1")
              {
              // user exists already
              return false;
              }
              else
              {
              return true;
              }
              }
              </script>

              <input name="username" >
              <input type="submit">
              </form>
              When I say "not work" I mean that the link was wrote not corrected and
              not work.
              Your approach appears to be wrong in the first place. See also
              <http://jibbering.com/faq/#FAQ4_24>.
              eg. When a user try to register to yahoo, when you write your
              username, sometime you receive a warning that your username is not
              available. I want to do the same.
              Are you sure this warning is displayed before the register form is
              submitted? If yes, you can simply look at Yahoo's source code to see how it
              was done client-side, and with Firebug and LiveHTTPHeaders you can see what
              is requested from the server and how the HTTP response looks like.


              HTH

              PointedEars
              --
              Use any version of Microsoft Frontpage to create your site.
              (This won't prevent people from viewing your source, but no one
              will want to steal it.)
              -- from <http://www.vortex-webdesign.com/help/hidesource.htm>

              Comment

              • pt36

                #8
                Re: append textbox value to href link before submit

                On 9 Lug, 10:01, pt36 <key.albe...@gm ail.comwrote:
                On 8 Lug, 12:49, sheldonlg <sheldonlgwrote :
                >
                >
                >
                >
                >
                pt36 wrote:
                Hi
                >
                I have a page with a form and a textbox.
                before to submit the form I want to chek if the inserted value in the
                textbox is already present in a database.
                So I need to pass the textbox value by a javascript link to another
                page to check.
                my code is
                <a href="javascrip t:location.href ='page_check.ph p' "Go check </a>
                and this work and open page_check.php
                >
                but when I want to append the textbox value, the code not work. I know
                I make mistake
                >
                <a href="javascrip t:location.href ='page_check.ph p?Box=' +
                document.formNa me.textboxName. value "Go check </a>
                >
                Any suggest ?
                Regards
                >
                Since checking of a database is done on the server, it seems to me that
                what you want is AJAX.  Have an "onclick=foo()" .  In foo you would make
                the AJAX call and return a message to the browser depending upon whether
                there is no match or is a match.  If this is for checking before
                submitting the page, then get rid of the check button, keep the action
                as the where you want the page submitted to, put a "return foo()" in the
                form definition, and return either false or true from foo.
                >
                What do you mean by it doesn't work?  Does the php file not see the
                value?  Does the php file see the value, but you don't get values back
                to the current page?  What happens?- Nascondi testo citato
                >
                - Mostra testo citato
                >
                ok Well
                i have a page that submit a form. In the page, near to the textbox
                when a user insert his nik, I want that the user be alerted that the
                nik inserted in the textbox is already used, so have to choose
                another. I will that this happen before to submit the form.
                In php after submitting the page I am able to check this, and also I
                not need help for the php code for this.
                I am able to make this procedure and see the alert in a new windows
                popup.
                I will that the alert appear in the page, near the textbox, (in a DIV)
                If an Ajax procedure helps me i say thanks, please send suggestions.
                >
                When I say "not work" I mean that the link was wrote not corrected and
                not work.
                if you write my code you see what happen
                In the first example the link open the page page_check.php
                In the second example the link not open the page_page.php and the link
                path is incorrect.
                >
                eg. When a user try to register to yahoo, when you write your
                username, sometime you receive a warning that your username is not
                available. I want to do the same.
                Regards- Nascondi testo citato
                >
                - Mostra testo citato
                I Found this good tutorial and I solved

                Thanks to all

                Comment

                • SAM

                  #9
                  Re: append textbox value to href link before submit

                  pt36 a écrit :
                  I will that the alert appear in the page, near the textbox, (in a DIV)
                  If an Ajax procedure helps me i say thanks, please send suggestions.
                  Put the file with your form in a tag "object"
                  The answer will be send back in the same tag (without needing Ajax)
                  That works almost like an iframe

                  Then ... what to do with the answer is another question ;-)

                  --
                  sm

                  Comment

                  • Doug Gunnoe

                    #10
                    Re: append textbox value to href link before submit

                    On Jul 8, 8:49 pm, Thomas 'PointedEars' Lahn <PointedE...@we b.de>
                    wrote:
                    This is but an invalid, inefficient, error-prone tag soup.
                    >
                    PointedEars
                    --
                    realism: HTML 4.01 Strict
                    evangelism: XHTML 1.0 Strict
                    madness: XHTML 1.1 as application/xhtml+xml
                    -- Bjoern Hoehrmann
                    Says you.

                    Anyway, sorry for the double post. I had some issues last night.

                    As to PointedEars comments, the answer I gave answered the question
                    she asked. Which I know is a rather difficult concept for you and a
                    few others to grasp. Not every question requires a lecture on
                    standards and specifications and best practice for crying out loud.

                    Furthermore, if I were trying to solve the problem she had, I would
                    have never used javascript. There is really no good reason to use it
                    for this problem, from what I can tell from her question.

                    But that's really not for me to say. She asked how to do something
                    using JavaScript and I gave her two workable solutions.

                    And don't respond to this with anything other than: "Yes Doug, you are
                    right and I, Thomas 'Pointed Ears' Lahn am wrong and humbly bey your
                    forgiveness".

                    And don't adjust the score either. So help me if you adjust the
                    score...

                    Comment

                    • Thomas 'PointedEars' Lahn

                      #11
                      Re: append textbox value to href link before submit

                      Doug Gunnoe wrote:
                      On Jul 8, 8:49 pm, Thomas 'PointedEars' Lahn <PointedE...@we b.de>
                      wrote:
                      >
                      >This is but an invalid, inefficient, error-prone tag soup.
                      >[...] -- Bjoern Hoehrmann
                      >
                      Says you.
                      And I also say to you: Learn to quote. Finally.
                      [...]
                      As to PointedEars comments, the answer I gave answered the question
                      she asked. Which I know is a rather difficult concept for you and a
                      few others to grasp.
                      We strive to provide the best possible answers here, not the quickest ones.


                      PointedEars
                      --
                      Anyone who slaps a 'this page is best viewed with Browser X' label on
                      a Web page appears to be yearning for the bad old days, before the Web,
                      when you had very little chance of reading a document written on another
                      computer, another word processor, or another network. -- Tim Berners-Lee

                      Comment

                      Working...