By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
437,636 Members | 1,213 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 437,636 IT Pros & Developers. It's quick & easy.

problem with some script

P: n/a
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=document.getElementById("checkInDate" ).value
ncheckInMonth=document.getElementById("month").val ue
ncheckInYear=document.getElementById("year").value
nnumberOfNights=document.getElementById("nights"). value
nnumberOfAdults=document.getElementById("adults"). value
nnumberOfRooms=document.getElementById("rooms").va lue

t="http://www.ichotelsgroup.com/redirect?checkInDatebrandCode=6c&path=asearc
h&city=London&countryId=0925&rateTypeCodes=6CBARC& checkInDate="+checkInDate+
"&checkInMonth="+month+"&checkInYear="+year+"&numb erOfNights="+nights+"&numb
erOfAdults="+adults+"&numberOfRooms="+rooms+"&hote lCode=LONLH"

alert(t)
location.href=t
}
</script>
Jul 20 '05 #1
Share this Question
Share on Google+
6 Replies


P: n/a
Hello,
ncheckInDate=document.getElementById("checkInDate" ).value 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" <ja***@legeo.co.dh> wrote in message
news:br**********@titan.btinternet.com... 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=document.getElementById("checkInDate" ).value
ncheckInMonth=document.getElementById("month").val ue
ncheckInYear=document.getElementById("year").value
nnumberOfNights=document.getElementById("nights"). value
nnumberOfAdults=document.getElementById("adults"). value
nnumberOfRooms=document.getElementById("rooms").va lue

t="http://www.ichotelsgroup.com/redirect?checkInDatebrandCode=6c&path=asearc h&city=London&countryId=0925&rateTypeCodes=6CBARC& checkInDate="+checkInDate+ "&checkInMonth="+month+"&checkInYear="+year+"&numb erOfNights="+nights+"&numb erOfAdults="+adults+"&numberOfRooms="+rooms+"&hote lCode=LONLH"

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

Jul 20 '05 #2

P: n/a
"james" <ja***@legeo.co.dh> wrote in message
news:br**********@titan.btinternet.com...
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=document.getElementById("checkInDate" ).value
Above you are creating a global variable with the name "ncheckInDate"
and assigning a value to it (assuming that the browser in use supports
document.getelementById 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.
ncheckInMonth=document.getElementById("month").val ue
Ditto.
ncheckInYear=document.getElementById("year").value
Ditto.
nnumberOfNights=document.getElementById("nights"). value
Ditto.
nnumberOfAdults=document.getElementById("adults"). value
Ditto.
nnumberOfRooms=document.getElementById("rooms").va lue

t="http://www.ichotelsgroup.com/redirect
?checkInDatebrandCode=6c&path=asearch&city=London &
countryId=0925&rateTypeCodes=6CBARC&checkInDate=" +checkInDate+
Above you have created a global variable with the identifier
"ncheckInDate" 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 "checkInDate" 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 "checkInDate", 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 "checkInDate" 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).
"&checkInMonth="+month+"&checkInYear="+year+
Ditto. ... etc.
"&numberOfNights="+nights+
"&numberOfAdults="+adults+
"&numberOfRooms="+rooms+"&hotelCode=LONLH"

alert(t)
location.href=t


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.
Jul 20 '05 #3

P: n/a
lallous wrote:
ncheckInDate=document.getElementById("checkInDate" ).value It seems the getElemenetById("checkInDate").value is returning an object and
not a value.


It does not seem so, and would contradict any DOM specification I have
read anyway. However, it is possible that document.getElementById(...)
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.getElementById)
{
ncheckInDate = document.getElementById(...);

/*
* 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.value != "undefined")
{
... ncheckInDate.value ...
}
...
}

This is a general method and of course applicable
but not efficient with form elements at all, since:
Try accessing the values of your 'checkInDate' and similar fields through
their form as:
theForm['checkInDate'].value
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.elements['checkInDate']
--
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.
[...]
[TOFU]


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
Jul 20 '05 #4

P: n/a
JRS: In article <br**********@titan.btinternet.com>, seen in
news:comp.lang.javascript, james <ja***@legeo.co.dh> posted at Thu, 11
Dec 2003 07:58:59 :-
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.
Please check your English before posting. Do not allow your posting
agent to break code lines. Use layout in your code for legibility,

function doURL() {
ncheckInDate=document.getElementById("checkInDate" ).value
ncheckInMonth=document.getElementById("month").val ue
ncheckInYear=document.getElementById("year").value
nnumberOfNights=document.getElementById("nights"). value
nnumberOfAdults=document.getElementById("adults"). value
nnumberOfRooms=document.getElementById("rooms").va lue

t="http://www.ichotelsgroup.com/redirect?checkInDatebrandCode=6c&path=asearc
h&city=London&countryId=0925&rateTypeCodes=6CBARC &checkInDate="+checkInDate+
"&checkInMonth="+month+"&checkInYear="+year+"&num berOfNights="+nights+"&numb
erOfAdults="+adults+"&numberOfRooms="+rooms+"&hot elCode=LONLH"

alert(t)
location.href=t
}


Your last line should be written as

t = "http://www.ichotelsgroup.com/redirect?checkInDatebrandCode=6c" +
"&path=asearch&city=London&countryId=0925&rateType Codes=6CBARC" +
"&checkInDate=" + checkInDate +
"&checkInMonth=" + month +
"&checkInYear=" + year +
"&numberOfNights=" + nights +
"&numberOfAdults=" + adults +
"&numberOfRooms=" + rooms +
"&hotelCode=LONLH"

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=document.getElementById("checkInDate" ).value

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

function Read(S) { return document.getElementById(S).value }

ncheckInDate = Read("checkInDate")
ncheckInMonth = Read("month")
// ...

and even end up with

t = ... +
"&checkInDate=" + Read("checkInDate") +
"&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.demon.co.uk/js-index.htm> Jsc maths, dates, sources.
<URL:http://www.merlyn.demon.co.uk/> TP/BP/Delphi/Jsc/&c, FAQ topics, links.
Jul 20 '05 #5

P: n/a
On Fri, 12 Dec 2003 21:01:56 +0000
Dr John Stockton <sp**@merlyn.demon.co.uk> wrote:
<snip>
Please check your English before posting. Do not allow your posting
agent to break code lines. Use layout in your code for legibility,
It looked to me like English was his second language, and much better
than my German.

<snip> Your last line should be written as

t = "http://www.ichotelsgroup.com/redirect?checkInDatebrandCode=6c" +
"&path=asearch&city=London&countryId=0925&rateType Codes=6CBARC" +
"&checkInDate=" + checkInDate +
"&checkInMonth=" + month +
"&checkInYear=" + year +
"&numberOfNights=" + nights +
"&numberOfAdults=" + adults +
"&numberOfRooms=" + rooms +
"&hotelCode=LONLH"

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


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
Jul 20 '05 #6

P: n/a
JRS: In article <20******************************@tcac.net>, seen in
news:comp.lang.javascript, Albert Wagner <al******@tcac.net> posted at
Fri, 12 Dec 2003 20:27:16 :-
On Fri, 12 Dec 2003 21:01:56 +0000
Dr John Stockton <sp**@merlyn.demon.co.uk> wrote:
<snip>
Please check your English before posting. Do not allow your posting
agent to break code lines. Use layout in your code for legibility,
It looked to me like English was his second language, and much better
than my German.


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.
<snip>
Your last line should be written as
...
Code that is illegibly-written is unlikely to be error-free.


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.


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.demon.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)
Jul 20 '05 #7

This discussion thread is closed

Replies have been disabled for this discussion.