Jump to content

Form Validation - checkbox (select only one)


brownbrod

Recommended Posts

Hi.  Just a quick question.   If you browse the web, I see that there are several form validations out there but they required JAVASCRIPT.   

 

I have serveral forms with CHECKBOX for survey questions.    Several of the questions only allow you to pick one box.    This is my form for one of the questions:

 

<form method="post" action="hasq3.php">
   <table border="0" width="100%">
   <tr>
    <td width="2%" height="30">
    <input type="checkbox" name="q2" value="Quality Plan Does Not Exist" tabindex="1"></td>
    <td width="103%" height="30">Quality Plan Does
    Not Exist</td>
   </tr>
   <tr>
    <td width="2%" height="30">
    <input type="checkbox" name="q2" value="Draft Quality Plan Exists" tabindex="2"></td>
    <td width="103%" height="30">Draft Quality Plan Exists</td>
   </tr>
   <tr>
    <td width="2%" height="30">
    <input type="checkbox" name="q2" value="Draft Quality Plan Following HW Quality Plan Template" tabindex="3"></td>
    <td width="103%" height="30">Draft Quality Plan Following HW Quality Plan Template</td>
   </tr>
   </tr>
   <td width="71%">
   <button type="submit">Next Page</button>
   </form>

 

Is there a way to instruct the PHP to only select one checkbox?     On another form I have an input box for "NAME".    Is there a way to say that this field is required?

 

If I use JAVA do I have to save the file as a .jsp file or can this be imbedded in the <Head></HEAD>.   I am not familiar with JAVA.

 

I greatly appreciate any help you can provide.

 

Thanks,

Link to comment
Share on other sites

I second ginerjm, if only one selection is allowed, you want a radio button or drop-down list. Also, you should use JavaScript for validation. Using PHP means that the person has to submit the form before they know that what they submit was invalid, unless you use Ajax (which uses JavaScript) which is going to require more work than just using JavaScript in the first place. Your PHP should also validate the information in case the user has JavaScript disabled, but you shouldn't make people wait to know they've input invalid information if at all possible.

 

You don't need to use Java. Java is not JavaScript.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.