problem with some script

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

    problem with some script

    CAn Some one please help when this scrip runs it does not enter the data
    from my forms, it just says[object] where each feild should be. I have
    tested it using google address and it appears to work just fine. But i
    cma't get it to work with the below link.

    Thanks james
    <script>
    function doURL() {
    ncheckInDate=do cument.getEleme ntById("checkIn Date").value
    ncheckInMonth=d ocument.getElem entById("month" ).value
    ncheckInYear=do cument.getEleme ntById("year"). value
    nnumberOfNights =document.getEl ementById("nigh ts").value
    nnumberOfAdults =document.getEl ementById("adul ts").value
    nnumberOfRooms= document.getEle mentById("rooms ").value

    t="http://www.ichotelsgro up.com/redirect?checkI nDatebrandCode= 6c&path=asearc
    h&city=London&c ountryId=0925&r ateTypeCodes=6C BARC&checkInDat e="+checkInDate +
    "&checkInMonth= "+month+"&check InYear="+year+" &numberOfNights ="+nights+"&num b
    erOfAdults="+ad ults+"&numberOf Rooms="+rooms+" &hotelCode=LONL H"



    alert(t)
    location.href=t
    }
    </script>


  • lallous

    #2
    Re: problem with some script

    Hello,[color=blue]
    > ncheckInDate=do cument.getEleme ntById("checkIn Date").value[/color]
    It seems the getElemenetById ("checkInDate") .value is returning an object and
    not a value.
    Try accessing the values of your 'checkInDate' and similar fields through
    their form as:
    theForm['checkInDate'].value

    --
    Elias

    "james" <james@legeo.co .dh> wrote in message
    news:br9843$dnl $1@titan.btinte rnet.com...[color=blue]
    > CAn Some one please help when this scrip runs it does not enter the data
    > from my forms, it just says[object] where each feild should be. I have
    > tested it using google address and it appears to work just fine. But i
    > cma't get it to work with the below link.
    >
    > Thanks james
    > <script>
    > function doURL() {
    > ncheckInDate=do cument.getEleme ntById("checkIn Date").value
    > ncheckInMonth=d ocument.getElem entById("month" ).value
    > ncheckInYear=do cument.getEleme ntById("year"). value
    > nnumberOfNights =document.getEl ementById("nigh ts").value
    > nnumberOfAdults =document.getEl ementById("adul ts").value
    > nnumberOfRooms= document.getEle mentById("rooms ").value
    >
    >[/color]
    t="http://www.ichotelsgro up.com/redirect?checkI nDatebrandCode= 6c&path=asearc[color=blue]
    >[/color]
    h&city=London&c ountryId=0925&r ateTypeCodes=6C BARC&checkInDat e="+checkInDate +[color=blue]
    >[/color]
    "&checkInMonth= "+month+"&check InYear="+year+" &numberOfNights ="+nights+"&num b[color=blue]
    > erOfAdults="+ad ults+"&numberOf Rooms="+rooms+" &hotelCode=LONL H"
    >
    >
    >
    > alert(t)
    > location.href=t
    > }
    > </script>
    >
    >[/color]


    Comment

    • Richard Cornford

      #3
      Re: problem with some script

      "james" <james@legeo.co .dh> wrote in message
      news:br9843$dnl $1@titan.btinte rnet.com...[color=blue]
      >CAn Some one please help when this scrip runs it does not enter
      >the data from my forms, it just says[object] where each feild
      >should be. I have tested it using google address and it appears
      >to work just fine. But i cma't get it to work with the below link.
      >
      > Thanks james
      > <script>
      > function doURL() {
      > ncheckInDate=do cument.getEleme ntById("checkIn Date").value[/color]

      Above you are creating a global variable with the name "ncheckInDa te"
      and assigning a value to it (assuming that the browser in use supports
      document.getele mentById and the call to that method returns an object
      reference, neither of which are certain). Needlessly creating global
      variables (indeed, giving variables any more scope than the absolute
      minimum (possible) they need) is bad programming. Prefixing the
      statement with the - var - keyword would declare the variable local to
      the function.
      [color=blue]
      > ncheckInMonth=d ocument.getElem entById("month" ).value[/color]

      Ditto.
      [color=blue]
      > ncheckInYear=do cument.getEleme ntById("year"). value[/color]

      Ditto.
      [color=blue]
      > nnumberOfNights =document.getEl ementById("nigh ts").value[/color]

      Ditto.
      [color=blue]
      > nnumberOfAdults =document.getEl ementById("adul ts").value[/color]

      Ditto.
      [color=blue]
      > nnumberOfRooms= document.getEle mentById("rooms ").value
      >
      >t="http://www.ichotelsgro up.com/redirect
      >?checkInDatebr andCode=6c&path =asearch&city=L ondon&
      >countryId=0925 &rateTypeCodes= 6CBARC&checkInD ate="+checkInDa te+[/color]

      Above you have created a global variable with the identifier
      "ncheckInDa te" and assigned it the value property of a (presumably form
      element) object (assuming browser support for the method used and
      correctly corresponding HTML). Here you are concatenating the value held
      by the identifier "checkInDat e" to the string. In fact you do not appear
      to be using any of the global variables created above in assembling this
      string.

      If we assume that the (unseen) HTML does contain a form element with the
      ID "checkInDat e", as is implied by the first call to the getElementById
      method, then some browsers (IE and followers) will have made a reference
      to that element into a global property with the name "checkInDat e" and
      the use of that identifier here will be resolved into a reference to
      that object. On IE almost all native objects type-convert to the string
      "[object]", which explains the reported results.

      The balance of probability is that you should be concatenating the
      global (but should be local) variable values into this string (otherwise
      there was not much point in creating them). However, if this string is
      going to be used as a URI (which it is) the values in the name/value
      pairs may need to be URI encoded, unless you have already verified that
      they only contain characters that would not be altered by URI encoding
      (it is user input so it could be anything).
      [color=blue]
      >"&checkInMonth ="+month+"&chec kInYear="+year+[/color]

      Ditto. ... etc.
      [color=blue]
      >"&numberOfNigh ts="+nights+
      >"&numberOfAdul ts="+adults+
      >"&numberOfRoom s="+rooms+"&hot elCode=LONLH"
      >
      > alert(t)
      > location.href=t[/color]

      Absolutely none of this is necessary, an appropriate HTML form and a
      properly constructed back-end could (and so should) do this job without
      even involving JavaScript, and do it better and more reliably. If this
      is a genuine hotel booking system (rather than an academic/training
      exercise that will never be used) you should bare in mind that your
      ignorance of what you are doing will directly result in an _unnecessary_
      and _avoidable_ loss of business for whoever it is that is employing
      you.

      Richard.


      Comment

      • Thomas 'PointedEars' Lahn

        #4
        Re: problem with some script

        lallous wrote:
        [color=blue][color=green]
        >> ncheckInDate=do cument.getEleme ntById("checkIn Date").value[/color]
        > It seems the getElemenetById ("checkInDate") .value is returning an object and
        > not a value.[/color]

        It does not seem so, and would contradict any DOM specification I have
        read anyway. However, it is possible that document.getEle mentById(...)
        returns, if supported, an undefined (!= `undefined') value if there is
        more than one element with that ID or a `null' value if there is none
        element with that ID. Thus one should always check the returned
        reference before accessing the object it references:

        if (document.getEl ementById)
        {
        ncheckInDate = document.getEle mentById(...);

        /*
        * Checks for a valid reference; can include combination with checks
        * for value to see that we got the correct object; however, using
        * multiple identical IDs is bad style if not even invalid HTML.
        */
        if (ncheckInDate && typeof ncheckInDate.va lue != "undefined" )
        {
        ... ncheckInDate.va lue ...
        }
        ...
        }

        This is a general method and of course applicable
        but not efficient with form elements at all, since:
        [color=blue]
        > Try accessing the values of your 'checkInDate' and similar fields through
        > their form as:
        > theForm['checkInDate'].value[/color]

        Assuming that `theForm' is a reference to the HTMLFormElement object,
        the standardized and therefore recommended method of accessing one of
        its child form elements is

        theForm.element s['checkInDate']
        [color=blue]
        > --[/color]

        A trailing space is needed for that to be a signature separator.
        Since OE is borken on that, you require additional tools or should
        just leave it out.
        [color=blue]
        > [...]
        > [TOFU][/color]

        Please stop doing that, bandwidth and disk space are precious. Instead,
        trim your quotes to the parts you are referring to and place the answer
        below the "question" as you see here.


        PointedEars

        Comment

        • Dr John Stockton

          #5
          Re: problem with some script

          JRS: In article <br9843$dnl$1@t itan.btinternet .com>, seen in
          news:comp.lang. javascript, james <james@legeo.co .dh> posted at Thu, 11
          Dec 2003 07:58:59 :-[color=blue]
          >CAn Some one please help when this scrip runs it does not enter the data
          >from my forms, it just says[object] where each feild should be. I have
          >tested it using google address and it appears to work just fine. But i
          >cma't get it to work with the below link.[/color]

          Please check your English before posting. Do not allow your posting
          agent to break code lines. Use layout in your code for legibility,

          [color=blue]
          > function doURL() {
          > ncheckInDate=do cument.getEleme ntById("checkIn Date").value
          > ncheckInMonth=d ocument.getElem entById("month" ).value
          > ncheckInYear=do cument.getEleme ntById("year"). value
          > nnumberOfNights =document.getEl ementById("nigh ts").value
          > nnumberOfAdults =document.getEl ementById("adul ts").value
          > nnumberOfRooms= document.getEle mentById("rooms ").value
          >
          >t="http://www.ichotelsgro up.com/redirect?checkI nDatebrandCode= 6c&path=asearc
          >h&city=London& countryId=0925& rateTypeCodes=6 CBARC&checkInDa te="+checkInDat e+
          >"&checkInMonth ="+month+"&chec kInYear="+year+ "&numberOfNight s="+nights+"&nu mb
          >erOfAdults="+a dults+"&numberO fRooms="+rooms+ "&hotelCode=LON LH"
          >
          >
          >
          > alert(t)
          > location.href=t
          >}[/color]

          Your last line should be written as

          t = "http://www.ichotelsgro up.com/redirect?checkI nDatebrandCode= 6c" +
          "&path=asearch& city=London&cou ntryId=0925&rat eTypeCodes=6CBA RC" +
          "&checkInDa te=" + checkInDate +
          "&checkInMonth= " + month +
          "&checkInYe ar=" + year +
          "&numberOfNight s=" + nights +
          "&numberOfAdult s=" + adults +
          "&numberOfRooms =" + rooms +
          "&hotelCode=LON LH"

          Code that is illegibly-written is unlikely to be error-free.

          It is now obvious that you have, at the right of six lines, names of
          form objects rather than the values you have read from them.


          ncheckInDate=do cument.getEleme ntById("checkIn Date").value

          and its mates are rather repetitive. ISTM that one should be able to
          write (untested)

          function Read(S) { return document.getEle mentById(S).val ue }

          ncheckInDate = Read("checkInDa te")
          ncheckInMonth = Read("month")
          // ...

          and even end up with

          t = ... +
          "&checkInDa te=" + Read("checkInDa te") +
          "&checkInMonth= " + Read("month") +
          ...

          --
          © John Stockton, Surrey, UK. ?@merlyn.demon. co.uk Turnpike v4.00 IE 4 ©
          <URL:http://jibbering.com/faq/> Jim Ley's FAQ for news:comp.lang. javascript
          <URL:http://www.merlyn.demo n.co.uk/js-index.htm> Jsc maths, dates, sources.
          <URL:http://www.merlyn.demo n.co.uk/> TP/BP/Delphi/Jsc/&c, FAQ topics, links.

          Comment

          • Albert Wagner

            #6
            Re: problem with some script

            On Fri, 12 Dec 2003 21:01:56 +0000
            Dr John Stockton <spam@merlyn.de mon.co.uk> wrote:
            <snip>[color=blue]
            > Please check your English before posting. Do not allow your posting
            > agent to break code lines. Use layout in your code for legibility,[/color]

            It looked to me like English was his second language, and much better
            than my German.

            <snip>[color=blue]
            > Your last line should be written as
            >
            > t = "http://www.ichotelsgro up.com/redirect?checkI nDatebrandCode= 6c" +
            > "&path=asearch& city=London&cou ntryId=0925&rat eTypeCodes=6CBA RC" +
            > "&checkInDa te=" + checkInDate +
            > "&checkInMonth= " + month +
            > "&checkInYe ar=" + year +
            > "&numberOfNight s=" + nights +
            > "&numberOfAdult s=" + adults +
            > "&numberOfRooms =" + rooms +
            > "&hotelCode=LON LH"
            >
            > Code that is illegibly-written is unlikely to be error-free.[/color]

            I suspect it probably was written something like your reformatted code
            above and had been run through a utility to discard extra white space to
            minimize download time.
            <snip>


            --
            "Rats and roaches live by competition under the laws of supply and
            demand. It is the privilege of human beings to live under the laws of
            justice and mercy."
            - Wendell Berry

            Comment

            • Dr John Stockton

              #7
              Re: problem with some script

              JRS: In article <20031212202716 .60e414e4.alwag ner@tcac.net>, seen in
              news:comp.lang. javascript, Albert Wagner <alwagner@tcac. net> posted at
              Fri, 12 Dec 2003 20:27:16 :-[color=blue]
              >On Fri, 12 Dec 2003 21:01:56 +0000
              >Dr John Stockton <spam@merlyn.de mon.co.uk> wrote:
              ><snip>[color=green]
              >> Please check your English before posting. Do not allow your posting
              >> agent to break code lines. Use layout in your code for legibility,[/color]
              >
              >It looked to me like English was his second language, and much better
              >than my German.[/color]

              Possibly so; but he is posting as James, via a British ISP, and should
              know better. One cannot expect a high literary standard from the
              recently-educated, but one who purports to be a programmer should at
              least be careful.
              [color=blue]
              ><snip>[color=green]
              >> Your last line should be written as
              >> ...
              >> Code that is illegibly-written is unlikely to be error-free.[/color]
              >
              >I suspect it probably was written something like your reformatted code
              >above and had been run through a utility to discard extra white space to
              >minimize download time.[/color]

              Possibly so. But, in that case, the compressed version should be used
              only for download, and the legible version should be retained for
              update, reading, discussion, and improvement.

              --
              © John Stockton, Surrey, UK. ?@merlyn.demon. co.uk Turnpike v4.00 MIME. ©
              Web <URL:http://www.merlyn.demo n.co.uk/> - FAQish topics, acronyms, & links.
              Proper <= 4-line sig. separator as above, a line exactly "-- " (SonOfRFC1036)
              Do not Mail News to me. Before a reply, quote with ">" or "> " (SonOfRFC1036)

              Comment

              Working...