1. Don't use on focus, use on click.  Users (well power users) and the
disabled tab through form fields, and if you do on focus it will empty to
form field even if they don't want to.

2.  When dealing with multiple fields I would recommend your using a
function in a script block kicked off by the onchange event.

Example:

<html>
        <head>
                <title>JS Test</title>
                <script>
                        function clearForm(){
                                document.myForm.myField1.value="";
                                document.myForm.myField2.value="";
                        }
                </script>
        </head>
        <body>
                <form name="myForm">
                        <input type="text" name="myField1" />
                        <input type="text" name="myField2" />
                        <input type="radio" name="myField3" onclick="return
clearForm()" />
                </form>
        </body>
</html>

Also a couple of other tips.

1. Try and use XHTML.  All attributes and tags need to be lower cased.
2. Only use pound signs when they are needed, same with parens.  
3. DO NOT use camel case inside a tag unless your referencing a variable,
everything else should be in lowers.
4. If you decide you don't want to create a function to handle this you can
string statements together in the event handler using the semi-colon ;
Example:

<input type="radio" name="clearFormButton"
onclick="document.myForm.myField1.value='';
document.myForm.myField2.value='';" />

One thing to be aware of with this is that you need to use different quotes,
one for CF/HTML and one for JS.

See you're declaring a string inside where your telling the object what
event handler to run, or in this case writing the event handler on the tag.
I use double quotes in tags, and singles in JS, it's a bit more difficult
when you're creating dynamic SQL as you have to use the single quote.

Anyway, hope it helps.

> -----Original Message-----
> From: Doug Brown [mailto:[EMAIL PROTECTED]
> Sent: Thursday, December 21, 2006 3:34 PM
> To: CF-Talk
> Subject: Javascript help
> 
> I have a form with 2 text fields and some radio button, and what I would
> like to do is clear any text in the text fields if any of the radio
> buttons are selected. I can do this with one text field, but not sure how
> to work it with two
> 
> This will work with one text field...
> 
>  <input type="text" name="Aquantity" size="5" maxlength="6" <cfif
> ClassAdDetails.quantity_option eq
> "quantity">value="#ClassAdDetails.AQuantity#"</cfif>>
> 
> <input type="radio" name="quantity_option" value="always_in_stock"
> onFocus="document.updClassified.Aquantity.value = ''">
> 
> 
> 
> But.....Say just one of these text fields have a value, how can I clear
> either one when I click on any one of the radio buttons.
> 
>  <input type="text" name="name1" value="#value#">
>  <input type="text" name="name2" value="#value#">
> 
> 
> <input type="radio" name="quantity_option" value="always_in_stock"
> onFocus="?">
> <input type="radio" name="quantity_option" value="always_in_stock"
> onFocus="?">
> <input type="radio" name="quantity_option" value="always_in_stock"
> onFocus="?">
> 
> 
> Doug B.
> 
> 

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~|
Create robust enterprise, web RIAs.
Upgrade & integrate Adobe Coldfusion MX7 with Flex 2
http://ad.doubleclick.net/clk;56760587;14748456;a?http://www.adobe.com/products/coldfusion/flex2/?sdid=LVNU

Archive: 
http://www.houseoffusion.com/groups/CF-Talk/message.cfm/messageid:264811
Subscription: http://www.houseoffusion.com/groups/CF-Talk/subscribe.cfm
Unsubscribe: 
http://www.houseoffusion.com/cf_lists/unsubscribe.cfm?user=11502.10531.4

Reply via email to