on the first question if you always want to set focus to FIRST element of
the FIRST form you can use:
<body onload="document.forms[0].elements[0].focus()">

on the second you can just loop over the elements array and grab what you
need

----- Original Message -----
From: "Timothy Lynn" <[EMAIL PROTECTED]>
To: "CF-Talk" <[EMAIL PROTECTED]>
Sent: Tuesday, July 31, 2001 1:18 PM
Subject: 2 javascript questions


> 'lo there,
>
> I'm working on the checkout portion of a shopping cart app. First part
> of my question is about setting the focus to the first element of the
> form. I have some code which does this:
>
> function toForm() {
>  document.form1.Firstname.focus();
> }
>
> It's called at body onLoad and this works fine. However, I'd like to
> make this code re-useable and place it in my site-wide javascript file.
> So I tried in my include file:
>
> function toForm(theForm, theField) {
>  document.theForm.theField.focus();
> }
>
> and then called it by:
>
> onLoad="toForm('form1','Firstname')
>
> However, I was getting errors stating that theForm and theField were
> null objects. Anybody see what I'm doing wrong here?
>
> Second question. I would also like to include the functionality to click
> on a checkbox to have your billing info carry over to your shipping
> information. Again, I can get this working in a static format, but I'd
> like to make it more reusable.
>
> function InitSaveVariables(form) {
>     ShipFirst = form.ShipFirst.value;
>     etc.
> }
> function ShipToBillPerson(form) {
>     if (form.copy.checked) {
>     InitSaveVariables(form);
>     form.ShipFirst.value = form.BillFirst.value;
>     etc.
>     }
>     else {
>         form.ShipFirst.value = ShipFirst;
>         etc.
>     }
> }
>
> Ideally, I'd like to be able to pass in the form and then have the
> function cycle through the fields in the form collection without having
> to explicitly name each field.
>
> I've put off really getting into javascript for too long, so I'm trying
> to use it more to get a better grasp. TIA for your help!
>
> -Tim
>
>
>
>
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Structure your ColdFusion code with Fusebox. Get the official book at 
http://www.fusionauthority.com/bkinfo.cfm
FAQ: http://www.thenetprofits.co.uk/coldfusion/faq
Archives: http://www.mail-archive.com/[email protected]/
Unsubscribe: http://www.houseoffusion.com/index.cfm?sidebar=lists

Reply via email to