Retrieving Form Value

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

    Retrieving Form Value

    I need a solution for the following, if anyone can think of one. :)

    I have:
    1 form on the page. (no name, no id value set.)
    3 hidden form elements named: catalog, vwoidc, oid

    !!! I can only include the javascript right after the body tag. The
    form is found near the end of the loaded page.


    <form action="actionU RL" method=post>
    <input type=hidden name=catalog value=store>
    <input type=hidden name=vwoidc value=69a6e1deb 02417250691>
    <input type=hidden name=oid value=60323></form>

    Everything I've tried needs to have the javascript executed after the
    page has been fully loaded.

    Thanks in advance!!

  • Mick White

    #2
    Re: Retrieving Form Value

    Cognizance wrote:
    [color=blue]
    > I need a solution for the following, if anyone can think of one. :)
    >
    > I have:
    > 1 form on the page. (no name, no id value set.)
    > 3 hidden form elements named: catalog, vwoidc, oid
    >
    > !!! I can only include the javascript right after the body tag. The
    > form is found near the end of the loaded page.
    >[/color]

    <body>
    <script type="text/javascript">
    onload=function (){ //do stuff with document.forms[0] }
    </script>

    Mick
    [color=blue]
    >
    > <form action="actionU RL" method=post>
    > <input type=hidden name=catalog value=store>
    > <input type=hidden name=vwoidc value=69a6e1deb 02417250691>
    > <input type=hidden name=oid value=60323></form>
    >
    > Everything I've tried needs to have the javascript executed after the
    > page has been fully loaded.
    >
    > Thanks in advance!!
    >[/color]

    Comment

    • ASM

      #3
      Re: Retrieving Form Value

      Cognizance wrote:[color=blue]
      >
      > Everything I've tried needs to have the javascript executed after the
      > page has been fully loaded.[/color]

      yes of course.
      JS can't read or write-in thomething that doesn't yet append



      --
      Stephane Moriaux et son [moins] vieux Mac

      Comment

      • Randy Webb

        #4
        Re: Retrieving Form Value

        ASM wrote:[color=blue]
        > Cognizance wrote:[color=green]
        > >[/color]
        >[color=green]
        >> Everything I've tried needs to have the javascript executed after the
        >> page has been fully loaded.[/color]
        >
        >
        > yes of course.[/color]

        No, not of course. JS doesnt need the page fully loaded, it needs what
        you are trying to access rendered/loaded.

        Create a test page that has 80,000 lines. At the top, right after the
        body, add a script block with an alert that does something with the
        previous code and you will be surprised that it will indeed read it
        before the page has loaded.

        --
        Randy
        comp.lang.javas cript FAQ - http://jibbering.com/faq & newsgroup weekly

        Comment

        • Matt Kruse

          #5
          Re: Retrieving Form Value

          Randy Webb wrote:[color=blue]
          > No, not of course. JS doesnt need the page fully loaded, it needs what
          > you are trying to access rendered/loaded.[/color]

          Is that necessarily true for all browsers?

          I remember some version of Netscape in the past that wouldn't expose any
          part of the document until it was done loading. So, putting <script> at the
          end of the <body> didn't work because you still couldn't access the
          contents.

          I've always wondered if any specs require that content be made available to
          script as soon as it is parsed, or if a browser could choose not to expose
          anything to script until everything is loaded.

          --
          Matt Kruse



          Comment

          • Cognizance

            #6
            Re: Retrieving Form Value

            I tried Mick's suggestion, and it seems to be the same issue. When I
            place the following at the end of the page (just before /body) it will
            work:

            onload=test();
            function test(){
            var iName = document.forms[0].elements[0].value;
            alert(iName);

            However, if it's at the top just after the body tag (where this script
            will be included) it will not work.

            Randy, I'm not sure I understand your suggestion. I'm not too great
            with javascript. Still just getting by. Could you please help clarify?

            Comment

            • Randy Webb

              #7
              Re: Retrieving Form Value

              Cognizance wrote:[color=blue]
              > I tried Mick's suggestion, and it seems to be the same issue. When I
              > place the following at the end of the page (just before /body) it will
              > work:
              >
              > onload=test();
              > function test(){
              > var iName = document.forms[0].elements[0].value;
              > alert(iName);[/color]

              It happened to work in a scenario, but it will not always work. The
              reason is that you shouldn't have the () on the first test.
              You are also missing a } at the end of your function.
              It should be:

              window.onload = test;

              When the browser sees the test() as you have it, it executes the
              function right then, not after onload fires.
              [color=blue]
              > However, if it's at the top just after the body tag (where this script
              > will be included) it will not work.[/color]

              See above.
              [color=blue]
              > Randy, I'm not sure I understand your suggestion. I'm not too great
              > with javascript. Still just getting by. Could you please help clarify?[/color]

              Try reading the FAQ with regards to posting/quoting.


              --
              Randy
              comp.lang.javas cript FAQ - http://jibbering.com/faq & newsgroup weekly

              Comment

              • Cognizance

                #8
                Re: Retrieving Form Value



                Randy Webb wrote:[color=blue]
                > It happened to work in a scenario, but it will not always work. The
                > reason is that you shouldn't have the () on the first test.
                > You are also missing a } at the end of your function.
                > It should be:
                >
                > window.onload = test;
                >
                > When the browser sees the test() as you have it, it executes the
                > function right then, not after onload fires.[/color]

                Sweet. That does the trick!! Thanks!

                [color=blue]
                > Try reading the FAQ with regards to posting/quoting.[/color]
                Are you referring to the FAQ referenced in your sig?
                (http://jibbering.com/faq)

                Comment

                • Randy Webb

                  #9
                  Re: Retrieving Form Value

                  Cognizance wrote:
                  [color=blue]
                  >
                  > Randy Webb wrote:
                  >[color=green]
                  >>It happened to work in a scenario, but it will not always work. The
                  >>reason is that you shouldn't have the () on the first test.
                  >>You are also missing a } at the end of your function.
                  >>It should be:
                  >>
                  >>window.onlo ad = test;
                  >>
                  >>When the browser sees the test() as you have it, it executes the
                  >>function right then, not after onload fires.[/color]
                  >
                  >
                  > Sweet. That does the trick!! Thanks!
                  >[/color]

                  Welcome.
                  [color=blue]
                  >[color=green]
                  >>Try reading the FAQ with regards to posting/quoting.[/color]
                  >
                  > Are you referring to the FAQ referenced in your sig?
                  > (http://jibbering.com/faq)[/color]

                  Yes.

                  --
                  Randy
                  comp.lang.javas cript FAQ - http://jibbering.com/faq & newsgroup weekly

                  Comment

                  • Mick White

                    #10
                    Re: Retrieving Form Value

                    Cognizance wrote:[color=blue]
                    > I tried Mick's suggestion, and it seems to be the same issue. When I
                    > place the following at the end of the page (just before /body) it will
                    > work:
                    >
                    > onload=test();
                    > function test(){
                    > var iName = document.forms[0].elements[0].value;
                    > alert(iName);
                    >
                    > However, if it's at the top just after the body tag (where this script
                    > will be included) it will not work.
                    >[/color]


                    I didn't suggest the stuff above, rather I suggested using an anonymous
                    function:
                    <body>
                    <script type="text/javascript">
                    onload=function (){alert(docume nt.forms[0].elements[0].value);}
                    </script>

                    Mick

                    Comment

                    • Cognizance

                      #11
                      Re: Retrieving Form Value

                      I have another question...

                      Mick White wrote:[color=blue]
                      > I didn't suggest the stuff above, rather I suggested using an anonymous
                      > function:
                      > <body>
                      > <script type="text/javascript">
                      > onload=function (){alert(docume nt.forms[0].elements[0].value);}
                      > </script>
                      >
                      > Mick[/color]

                      Sorry for the confusion, Mick. I was able to get the function to
                      execute properly. My current script looks like:

                      <!--
                      window.onload = getTotal;

                      function getTotal(){
                      var oDiv = document.getEle mentsByTagName( "body");
                      var pBody = oDiv[0];
                      var bTags = pBody.getElemen tsByTagName("b" );

                      for (var iii = 0; iii < bTags.length; iii++) {

                      var cText = bTags[iii].innerHTML;
                      if (cText.match(/^\d+?\.\d{2}$/)) {
                      var theValue = cText;
                      var theOrderID = document.forms[0].oid.value;

                      var tagstr = "<img
                      src=\"https://switch.atdmt.co m/action/adolmb_confirma tionpage_7/v3/ato."
                      + theOrderID + "/atm1." + theValue + "/\">";
                      var loadURL =
                      "https://switch.atdmt.co m/action/adolmb_confirma tionpage_7/v3/ato." +
                      theOrderID + "/atm1." + theValue;
                      alert(loadURL);
                      //document.write( tagstr);
                      document.load(l oadURL);
                      }
                      }
                      }
                      //-->

                      Now what I need to do... I need to somehow be able to "hit" the loadURL
                      that's created. Is there a way to hit an URL without losing the current
                      document loaded?

                      Comment

                      • Mick White

                        #12
                        Re: Retrieving Form Value

                        Cognizance wrote:
                        [color=blue]
                        >
                        > Sorry for the confusion, Mick. I was able to get the function to
                        > execute properly. My current script looks like:
                        >
                        > <!--
                        > window.onload = getTotal;
                        >
                        > function getTotal(){
                        > var oDiv = document.getEle mentsByTagName( "body");
                        > var pBody = oDiv[0];
                        > var bTags = pBody.getElemen tsByTagName("b" );
                        >
                        > for (var iii = 0; iii < bTags.length; iii++) {
                        >
                        > var cText = bTags[iii].innerHTML;
                        > if (cText.match(/^\d+?\.\d{2}$/)) {
                        > var theValue = cText;
                        > var theOrderID = document.forms[0].oid.value;
                        >
                        > var tagstr = "<img
                        > src=\"https://switch.atdmt.co m/action/adolmb_confirma tionpage_7/v3/ato."
                        > + theOrderID + "/atm1." + theValue + "/\">";
                        > var loadURL =
                        > "https://switch.atdmt.co m/action/adolmb_confirma tionpage_7/v3/ato." +
                        > theOrderID + "/atm1." + theValue;
                        > alert(loadURL);
                        > //document.write( tagstr);
                        > document.load(l oadURL);
                        > }
                        > }
                        > }
                        > //-->
                        >
                        > Now what I need to do... I need to somehow be able to "hit" the loadURL
                        > that's created. Is there a way to hit an URL without losing the current
                        > document loaded?[/color]

                        var w=window.open(l oadURL) perhaps?
                        Mick

                        Comment

                        • Cognizance

                          #13
                          Re: Retrieving Form Value



                          Mick White wrote:[color=blue][color=green]
                          > > Now what I need to do... I need to somehow be able to "hit" the loadURL
                          > > that's created. Is there a way to hit an URL without losing the current
                          > > document loaded?[/color]
                          >
                          > var w=window.open(l oadURL) perhaps?
                          > Mick[/color]

                          This seems to want to spawn a new browser window. I want it to be
                          transparent to the client. I want to keep the initial main page loaded,
                          and only want to hit the url determined by the javascript, keeping the
                          main page in view.

                          Is there a way to hit a URL in the background?

                          Comment

                          • Cognizance

                            #14
                            Re: Retrieving Form Value

                            > This seems to want to spawn a new browser window. I want it to be[color=blue]
                            > transparent to the client. I want to keep the initial main page loaded,
                            > and only want to hit the url determined by the javascript, keeping the
                            > main page in view.
                            >
                            > Is there a way to hit a URL in the background?[/color]

                            Well gang, I've figured out a way to accomplish what I needed!

                            <script language="javas cript">
                            <!--
                            window.onload = getTotal;

                            function getTotal(){
                            var oDiv = document.getEle mentsByTagName( "body");
                            var pBody = oDiv[0];
                            var bTags = pBody.getElemen tsByTagName("b" );

                            for (var iii = 0; iii < bTags.length; iii++) {

                            var cText = bTags[iii].innerHTML;
                            if (cText.match(/^\d+?\.\d{2}$/)) {
                            var theValue = cText;
                            var theOrderID = document.forms[0].oid.value;

                            var tagstr = "<img
                            src=\"https://switch.atdmt.co m/action/adolmb_confirma tionpage_7/v3/ato."
                            + theOrderID + "/atm1." + theValue + "/\">";
                            //var loadURL =
                            "https://switch.atdmt.co m/action/adolmb_confirma tionpage_7/v3/ato." +
                            theOrderID + "/atm1." + theValue;
                            var loadURL =
                            "https://home.americanap parel.net/test/Sample.jpg?Orde rID=" +
                            theOrderID + "&Total=" + theValue;
                            alert(loadURL);

                            Image1= new Image(175,50);
                            Image1.src = loadURL;

                            Image2= new Image(175,50);
                            Image2.src = "https://home.americanap parel.net/60323.gif";
                            }
                            }
                            }
                            //-->
                            </script>


                            Using the preload concept, I'm able to hit the URL in question.

                            Thanks to those who tried to hook me up with this one! ^^

                            Comment

                            • Lee

                              #15
                              Re: Retrieving Form Value

                              Cognizance said:
                              [color=blue]
                              ><script language="javas cript">
                              ><!--
                              >//-->
                              ></script>[/color]

                              I didn't look at your problem (which you seem to have solved),
                              but the above bits should be replaced by:

                              <script type="text/javascript">
                              </script>

                              The comments no longer serve any purpose, since there hasn't
                              been a browser in use in some time that doesn't understand
                              the <script> tag.

                              Comment

                              Working...