button linke value

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

    button linke value

    Hi there, newbie here.

    appologies if this is OT. (DOM based)

    I have a button defined in the html as follows:

    <input name="btnPay" value="Continue with payment"
    onclick="docume nt.location='Lo adPayment.asp?T PID=23448&RGID= 7'"
    type="button">< br>

    How can I extract the document.locati on portion from the html?
    IOW. 'LoadPayment.as p?TPID=23448&RG ID=7'

    Many TIA
    T

  • ZER0

    #2
    Re: button linke value

    On 15 Dec 2004 05:16:52 -0800, terti wrote:
    [color=blue]
    > <input name="btnPay" value="Continue with payment"
    > onclick="docume nt.location='Lo adPayment.asp?T PID=23448&RGID= 7'"
    > type="button">< br>[/color]
    [color=blue]
    > How can I extract the document.locati on portion from the html?
    > IOW. 'LoadPayment.as p?TPID=23448&RG ID=7'[/color]

    I don't know why you need to do it, it's a bit "ugly".. BTW, a method could
    be:

    <input id="btn-pay" name="btnPay" value="Continue with payment"
    onclick="docume nt.location='Lo adPayment.asp?T PID=23448&RGID= 7'"
    type="button">

    <script type="text/javascript">
    function getPayURI(){
    var btn=document.ge tElementById("b tn-pay"),
    txt=btn.getAttr ibute("onclick" ),
    res=[];

    txt=typeof txt=="function" ?txt.toString() :txt;

    res=txt.match(/document\.locat ion='([^']+)'/);

    return (res && res[1])?res[1]:null;
    }

    alert(getPayURI ())
    </script>

    --
    ZER0

    ~ The Tangent Universe collapsed 5890 days, 8 hours, 30 minutes and 35 seconds ago.

    on air ~ "The Church - Under The Milky Way Tonight"

    Comment

    • terti

      #3
      Re: button linke value

      Thanks for the reply,

      I can not alter the html that is sent to me so the getElementById( ) may
      not work
      What I really wanty to do is to simmilate a button being pressed
      without user intervention.


      The reason why I wanted the link was so that I could follow it with a
      get() method.
      Is there a way to simmulate a butted pressed event ?

      thanks
      T

      Comment

      • ZER0

        #4
        Re: button linke value

        On 15 Dec 2004 05:53:52 -0800, terti wrote:
        [color=blue]
        > Thanks for the reply,
        >
        > I can not alter the html that is sent to me so the getElementById( ) may
        > not work[/color]

        This is not a problem, you can use getElementsByTa gName instead:

        var btn=document.ge tElementsByTagN ame("btnPay")[0]
        [color=blue]
        > What I really wanty to do is to simmilate a button being pressed
        > without user intervention.[/color]

        You can try with click() method, then.

        document.getEle mentsByTagName( "btnPay")[0].click();

        --
        ZER0

        ~ The Tangent Universe collapsed 5890 days, 9 hours, 18 minutes and 41 seconds ago.

        on air ~ "Donnie Darko - Cellar Door"

        Comment

        • Ivo

          #5
          Re: button linke value

          "terti" wrote[color=blue]
          > Thanks for the reply,
          >
          > I can not alter the html that is sent to me so the getElementById( ) may
          > not work
          > What I really wanty to do is to simmilate a button being pressed
          > without user intervention.[/color]

          You don't need getElementById( ). The following code will loop through all
          input's on the page (in reverse order btw, that 's usually faster this way)
          and activite the first it finds that points to said url:

          var a=document.getE lementsByTagNam e('input');
          var i=a.length; while(i--) {
          if( a[i].type.toLowerCa se()==='button'
          && a[i].onclick.indexO f('LoadPayment. asp')>0 ) {
          a[i].click();
          }
          }

          Are you sure this is within the law?
          --
          Ivo


          Comment

          • terti

            #6
            Re: button linke value

            Many thanks for the help
            the .click() method gets the job done.

            Regrds
            T

            Comment

            • ZER0

              #7
              Re: button linke value

              On Wed, 15 Dec 2004 15:18:41 +0100, ZER0 wrote:
              [color=blue]
              > On 15 Dec 2004 05:53:52 -0800, terti wrote:
              >[color=green]
              >> Thanks for the reply,
              >>
              >> I can not alter the html that is sent to me so the getElementById( ) may
              >> not work[/color]
              >
              > This is not a problem, you can use getElementsByTa gName instead:
              >
              > var btn=document.ge tElementsByTagN ame("btnPay")[0][/color]

              Argh, sorry.. I was misunderstandin g:

              var btn=document.ge tElementsNames( "btnPay")[0]

              --
              ZER0

              ~ The Tangent Universe collapsed 5890 days, 9 hours, 53 minutes and 20 seconds ago.

              on air ~ "donny darko - Mad World (full version)"

              Comment

              • ZER0

                #8
                Re: button linke value

                On Wed, 15 Dec 2004 15:31:57 +0100, Ivo wrote:
                [color=blue]
                > You don't need getElementById( ). The following code will loop through all
                > input's on the page (in reverse order btw, that 's usually faster this way)[/color]

                You can use document.getEle mentsNames("btn Pay")[0] for obtain the reference
                to button.. The loop is not necessary:

                document.getEle mentsNames("btn Pay")[0].click()

                --
                ZER0

                ~ The Tangent Universe collapsed 5890 days, 9 hours, 55 minutes and 56 seconds ago.

                on air ~ "donny darko - Mad World (full version)"

                Comment

                • Michael Winter

                  #9
                  Re: button linke value

                  On Wed, 15 Dec 2004 15:55:56 +0100, ZER0 <zer0.shock@lib ero.it> wrote:

                  [snip]
                  [color=blue]
                  > You can use document.getEle mentsNames("btn Pay")[0][/color]

                  The name is getElementsByNa me, but considering that this control is in a
                  form,

                  document.forms[...].elements['btnPay']

                  where the ellipsis is either a number or a string containing the name or
                  id of the form, would be better.

                  [snip]

                  Mike

                  --
                  Michael Winter
                  Replace ".invalid" with ".uk" to reply by e-mail.

                  Comment

                  • ZER0

                    #10
                    Re: button linke value

                    On Wed, 15 Dec 2004 15:40:58 GMT, Michael Winter wrote:
                    [color=blue][color=green]
                    >> You can use document.getEle mentsNames("btn Pay")[0][/color][/color]
                    [color=blue]
                    > The name is getElementsByNa me,[/color]

                    yes, I misunderstandin g again.. unfortunately, I've made a copy&paste in
                    my post.. :) but the concept is the same.
                    [color=blue]
                    > but considering that this control is in a form,[/color]

                    well, I don't know if the control is in a form. In the post of terti the
                    code is out of context.
                    So, I wrote a code that works with or without a form parent element.
                    [color=blue]
                    > document.forms[...].elements['btnPay'][/color]

                    In that case you can use directly:

                    document.forms[...].btnPay.click() ;

                    or

                    document.forms. nameOfForm.btnP ay.click();

                    as well.

                    P.S.
                    Sorry for my english, I know is not very good.

                    --
                    ZER0

                    ~ The Tangent Universe collapsed 5890 days, 10 hours, 50 minutes and 24 seconds ago.

                    on air ~ "Tears For Fears - Head Over Heels"

                    Comment

                    • Michael Winter

                      #11
                      Re: button linke value

                      On Wed, 15 Dec 2004 16:50:24 +0100, ZER0 <zer0.shock@lib ero.it> wrote:

                      [snip]
                      [color=blue]
                      > well, I don't know if the control is in a form.[/color]

                      Re-examining the original post, it might not be. The text of the button,
                      "Continue with payment", would suggest that it is a submit button, but
                      it's not.

                      [snip]

                      Mike

                      --
                      Michael Winter
                      Replace ".invalid" with ".uk" to reply by e-mail.

                      Comment

                      • Rob B

                        #12
                        Re: button linke value



                        terti wrote:
                        [color=blue]
                        > Hi there, newbie here.[/color]
                        [color=blue]
                        > appologies if this is OT. (DOM based)[/color]
                        [color=blue]
                        > I have a button defined in the html as follows:[/color]
                        [color=blue]
                        > <input name="btnPay" value="Continue with payment"
                        > onclick="docume nt.location='lo adpayment.asp?t pid=23448&rgid= 7'"
                        > type="button">< br>[/color]
                        [color=blue]
                        > How can I extract the document.locati on portion from the html?
                        > IOW. 'loadpayment.as p?tpid=23448&rg id=7'[/color]

                        <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
                        "http://www.w3.org/TR/html4/strict.dtd">
                        <html>
                        <head>
                        <title>untitled </title>
                        <script type="text/javascript">

                        function bclick(bname)
                        {
                        var i = 0,
                        el,
                        els,
                        f,
                        fs = document.forms;
                        while ((f = fs[i++]) && (els = f.elements))
                        if ((el = els[bname]) && null != el.onclick)
                        el.onclick();
                        }

                        setTimeout('bcl ick("btnPay")', 3000);

                        </script>
                        </head>
                        <body>
                        <form>
                        <input name="btnPay" value="Continue with payment"
                        onclick="docume nt.location='lo adpayment.asp?t pid=23448&rgid= 7'"
                        type="button">
                        </form>
                        </body>
                        </html>

                        The button's name would suggest that it is in a (payment) form.

                        btw irrelevant but it's *window.locatio n*; document.locati on has been
                        deprecated for years although all browsers appear to have mapped it to
                        window.location .


                        *** Sent via Developersdex http://www.developersdex.com ***
                        Don't just participate in USENET...get rewarded for it!

                        Comment

                        Working...