开发者

checkboxes select choices at the same time

i have this code where you can select the date you like to attend the meeting. How can I have this possible to select 2 dates at the same time? Because in this code, one can only select 1 date. What should I add in here?

       <div style="background-color:#aaa">
       <form method="post" action="[~[*id*]~]">
       <input type="hidden" name="formid" value="registrationForm" />

       <p>
       <table>

       <tr>
       <td><label for="workshop" style="margin:0.5em">Termine:</label>
       <td>
       <input type="checkbox" name="termine1" value="Montag 4. Oktober 2010" eform="Termine::1"/>&#09;Montag 4. Oktober 2010 <br/>
        <input type="checkbox" name="termine2" value="Mittwoch 13. Oktober 2010" />&#09;Mittwoch 13. Oktober 2010 <br/>
        <input type="checkbox" name="termine3" value="Freitag 22. Oktober 2010" />&#09;Freitag 22. Oktober 2010 <br/>           
    </td>
</tr>   

<tr>
    <td><label for="email" style="margin:0.5em">Email:</label></td>
    <td><input type="text" name="email" size="60" maxlength="60" eform="Email:email:1" /><td>
</tr>
  <tr>
    <td><label style="margin:0.5em; display:block" for="kopieren" >Bitte kopieren Sie den Anti-Spam Code ein: </label>
    <img src="[+verimageurl+]" alt="verification code" border="1" style="margin:0.5em"/></td>
    <td valign="top"><input type="text" name="vericode" size="20" />
</tr>


   <tr>
    <td rowspan="3" valign="right">
        <input align="right" type="submit" name="submit" style="margin:0.5em" value="Register" />
    </td>
</tr>

</table>

=========

This would be the other form look like, do I need to add here for the other dates?

  <h3>Registration</h3>



 <table>
<开发者_StackOverflow中文版tr valign="top"><td>Termine</td><td>[+termine1+]</td></tr>
<tr valign="top"><td>Termine</td><td>[+termine2+]</td></tr>  
<tr valign="top"><td>Termine</td><td>[+termine3+]</td></tr>          
<tr valign="top"><td>Email</td><td>[+email+]</td></tr>    
 </table>


Make them Checkboxes instead?

<input type="checkbox" name="workshop1" value="morning-with-visit" eform="Selected Dates::1"/>&#09;18 August 2010<br/>
<input type="checkbox" name="workshop2" value="morning-without-visit" />&#09;19 August 2010<br/>
<input type="checkbox" name="workshop3" value="afternoon-with-visit" />&#09;20 August 2010 (12h50)<br/>  

Try it out here.


Change the inputs to type="checkbox". You will likely need to change the name attribute to correctly process server-side, assuming that's what you're doing.


I agree with the three answers supplied that you should use checkboxes, thus:

    <input type="checkbox" name="morning-with-visit" eform="Selected Dates::1"/>&#09;18 August 2010<br/>
    <input type="radio" name="morning-without-visit" />&#09;19 August 2010<br/>
    <input type="radio" name="afternoon-with-visit" />&#09;20 August 2010 (12h50)<br/>

On the server-side, you will only receive back the boxes that were ticked. Here is a PHP example...

if (isset($_POST['morning-with-visit'])) {
    echo 'They selected "morning-with-visit"';
}

You can make radio inputs multi-selectable, but by putting each in its own name... like this example (I only mention it to say that is IS possible).

    <input type="radio" name="workshop1" value="morning-with-visit" eform="Selected Dates::1"/>&#09;18 August 2010<br/>
    <input type="radio" name="workshop2" value="morning-without-visit" />&#09;19 August 2010<br/>
    <input type="radio" name="workshop3" value="afternoon-with-visit" />&#09;20 August 2010 (12h50)<br/> 

Note that if you do this, you can't actually "un-select" anything, which is bad. So many people use yes-no groups (although checkboxes are more natural for this).


You can't have multiple selections in a radio group. You need to use something like chekboxes and perform the validation yourself, to make sure that 2 values are selected. This can be done using javascript to get client-side validation before posting the values to the server.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜