How can I know which checkbox has been selected

Ilianam
Ilianam used Ask the Experts™
on
How can I know which text box has been checked?. visit http://www.bestsaveandtravel.com/
<form id="form1" name="form1" method="post" action="">
        <h3>
          <label>
            <input type="checkbox" name="chkService" value="checkbox" id="chkService_0" />
            Flight</label>
          <br />
          <label>
            <input type="checkbox" name="chkService" value="checkbox" id="chkService_1" />
            Car</label>
          <br />
          <label>
            <input type="checkbox" name="chkService" value="checkbox" id="chkService_2" />
            Hotel</label>
          <br />
          <label>
            <input type="checkbox" name="chkService" value="checkbox" id="chkService_3" />
            Cruise</label>
          <br />
        </h3>
      </form>

Open in new window

Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Jason C. LevineDon't talk to me.

Commented:
Hi Ilianam,

You need to add a server-side script that will process the form and do something with the data.  What do you want to happen and what languages are available to you?

Author

Commented:
Visual Studio vb.net
Jason C. LevineDon't talk to me.

Commented:
Let me get a Moderator to switch up the Zones for you, then.
Starting with Angular 5

Learn the essential features and functions of the popular JavaScript framework for building mobile, desktop and web applications.

Seven priceFull Stack

Commented:
<asp:CheckBox ID="CheckBox1" AutoPostBack="true" runat="server" />
and you can add a label to find out.

Seven priceFull Stack

Commented:
Front end
<asp:CheckBox ID="cbCheck" AutoPostBack="True" Runat="server" OnCheckedChanged="cbCheckOFF_OnCheckedChanged" Checked="false" Text="text" />



back end vb
 Protected Sub cbCheckOFF_OnCheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cbCheckOFF.CheckedChanged


        Dim CBL As CheckBox = CType(sender, CheckBox)

        If CBL.Checked Then
           
            'Label2.Text = "Now Active"
        End If


    End Sub
Top Expert 2013

Commented:

Author

Commented:
where I'm going to paste that code?
Hi,

You need to use the attribute runat="server" on the <form ..> tag.
Then also the same attribute must be on each checkbox.

Now you have 2 options to implement.
A) Using ASP.Net Server Control (e.g. a Button): Check each check box by using

Dim my1stCheckBox As System.Web.UI.HtmlControls.HtmlInputCheckBox = CType(Me.Form.FindControl("idOfEachCheckBox"),System.Web.UI.HtmlControls.HtmlInputCheckBox)
Dim areMy1stCheckBoxChecked As Boolean=myCheckBox.Checked

B)Using classic HTML

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial