James Walker wrote on 15 Dec 2003 at Mon, 15 Dec 2003 22:08:15
GMT:
[color=blue]
> Can some one help I get an error of 'checkIndate' is null or not
> an object
>
> can someone please help. I can't work out why[/color]
You capitalised it incorrectly. The control's name is 'checkInDate':
note the capital 'D'. JavaScript is case-sensitive.
Now for some unrelated comments...
Don't use a FORM that you don't intend to submit. It's an abuse of
the element. Form controls can exist and be referenced outside of a
FORM element, so there is no reason to use it[1].
In the code below, you reference ID values. That will only work in IE
(and possibly Opera). Furthermore, using code like:
document.booknow
can mean that your page will not work in some browsers. Instead, use:
document.forms['booknow']
and when accessing form elements:
document.forms['booknow'].elements['checkInDate']
In the future, if you use code like this, use name and id attributes
with the same values.
To access a form element without an enclosing form, use the
document.getElementById method (NS, Mozilla, Opera) or document.all
collection (IE, Opera). For example:
var checkInDate = null;
if (document.getElementById) {
checkInDate = document.getElementById('checkInDate');
} else if (document.all) {
checkInDate = document.all['checkInDate'];
}
if (checkInDate) {
// continue...
}
[color=blue]
> <script language="JavaScript">[/color]
The type attribute is *required* in HTML. When used, it renders the
deprecated language redundant.
<SCRIPT type="text/javascript">
[color=blue]
> function doURL()
> {
> var theForm=document.booknow;
> var checkInDate =
> theForm.checkIndate[checkInDate.selectedIndex].value;[/color]
You should be consistent with qualifying object references. This like
will probably produce unexpected results as you have a variable named
checkInDate and an object named checkInDate. However, as you don't
qualify the object properly, the variable will take presidence (not
what you want). This could be another source of the error.
You should have at least used theForm.checkInDate.selectedIndex,
though preferably you should use the methods I presented above. The
same applies to the next five lines.
[color=blue]
> var checkInMonth=theForm.month[month.selectedIndex].value;
> var checkInYear=theForm.year[year.selectedIndex].value;
> var numberOfNights=theForm.nights[nights.selectedIndex].value;
> var numberOfAdults=theForm.adults[adults.selectedindex].value;
> var numberOfRooms=theForm.rooms[rooms.selectedIndex].value;
> 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"[/color]
You missed the semi-colon here...
[color=blue]
> window.open(t,"_blank","")[/color]
....and here. Also, you declared 't' above globally. Use var like the
other declarations.
[color=blue]
> }
>
> //-->[/color]
Why is this here?
1) There isn't a starting comment sequence.
2) There is no longer a need to 'hide' scripts from browsers with
SGML comments, so it shouldn't be present anyway.
[color=blue]
> </script>[/color]
Mike
[1] Old browsers don't support DOM or DHTML, one of which is required
to access HTML elements that are not accessible through
collections, like document.forms.
--
Michael Winter
M.Winter@blueyonder.co.invalid (replace ".invalid" with ".uk")