On Wednesday, January 21, 2004, at 01:04  PM, Robert Orlini wrote:

> Anyone have a quick _javascript_ code top check if a certain radio
> button is selected then a input field must have content?

Here's a two minute solution:

<html>
     <head>
         <script language="_javascript_">
             function checkForm()
             {
                 var f = document.myForm;
                 for (var i = 0; i < f.paymentmethod.length; ++i)
                 {
                     if (f.paymentmethod[i].value == "cc")
                     {
                         if (f.paymentmethod[i].checked && f.ccNum.value
== "") //maybe replace with an RE
                         {
                             alert("Please fill in a credit card
number.");
                             return false;
                         }
                         return true;
                     }
                 }
                 return true;
             }
         </script>
     </head>
     <body>
         <form name="myForm" checkForm()">
             Purchase order: <input type="radio" name="paymentmethod"
value="po"/><br>
             Credit card: <input type="radio" name="paymentmethod"
value="cc"/>
             <input type="text" name="ccNum"/><br>
             <input type="submit" value="Submit"/>
         </form>
     </body>
</html>

Christian
[Todays Threads] [This Message] [Subscription] [Fast Unsubscribe] [User Settings]

Reply via email to