Setting Checkbox clientside

Discussion in 'ASP .Net' started by tshad, Dec 2, 2005.

  1. tshad

    tshad Guest

    I am trying to set and clear my checkboxes using client-side validation.

    I have some Javascript to set my checkboxes:

    <script language=javascript>
    function validate(){
    Medical.checked = 1;
    }
    </script>

    I get an error that says:

    "Medical" is undefined

    Here is my asp code:

    <asp:CheckBox id="Medical" Text="Medical" Checked="false"
    runat="server"/>

    and when I look at my page from view source:

    <input id="Medical" type="checkbox" name="Medical" /><label
    for="Medical">Medical</label>

    There is the name "Medical" - so why is Javascript saying it is undefined?

    Thanks,

    Tom
     
    tshad, Dec 2, 2005
    #1
    1. Advertising

  2. tshad

    CK Guest

    function validate()
    {
    var Medical = document.getElementById('Medical');
    //alert(Medical.checked);
    Medical.checked = true; //I think it's something like this
    }

    Hope this helps.
    CK

    "tshad" <> wrote in message
    news:%...
    >I am trying to set and clear my checkboxes using client-side validation.
    >
    > I have some Javascript to set my checkboxes:
    >
    > <script language=javascript>
    > function validate(){
    > Medical.checked = 1;
    > }
    > </script>
    >
    > I get an error that says:
    >
    > "Medical" is undefined
    >
    > Here is my asp code:
    >
    > <asp:CheckBox id="Medical" Text="Medical" Checked="false"
    > runat="server"/>
    >
    > and when I look at my page from view source:
    >
    > <input id="Medical" type="checkbox" name="Medical" /><label
    > for="Medical">Medical</label>
    >
    > There is the name "Medical" - so why is Javascript saying it is undefined?
    >
    > Thanks,
    >
    > Tom
    >
     
    CK, Dec 2, 2005
    #2
    1. Advertising

  3. tshad

    tshad Guest

    "CK" <> wrote in message
    news:cy3kf.26631$q%...
    > function validate()
    > {
    > var Medical = document.getElementById('Medical');
    > //alert(Medical.checked);
    > Medical.checked = true; //I think it's something like this
    > }


    Works perfectly.

    Would this be the same for all browsers?

    I am mainly worried about IE, but there are others that may use other
    browsers.

    Thanks,

    Tom
    >
    > Hope this helps.
    > CK
    >
    > "tshad" <> wrote in message
    > news:%...
    >>I am trying to set and clear my checkboxes using client-side validation.
    >>
    >> I have some Javascript to set my checkboxes:
    >>
    >> <script language=javascript>
    >> function validate(){
    >> Medical.checked = 1;
    >> }
    >> </script>
    >>
    >> I get an error that says:
    >>
    >> "Medical" is undefined
    >>
    >> Here is my asp code:
    >>
    >> <asp:CheckBox id="Medical" Text="Medical" Checked="false"
    >> runat="server"/>
    >>
    >> and when I look at my page from view source:
    >>
    >> <input id="Medical" type="checkbox" name="Medical" /><label
    >> for="Medical">Medical</label>
    >>
    >> There is the name "Medical" - so why is Javascript saying it is
    >> undefined?
    >>
    >> Thanks,
    >>
    >> Tom
    >>

    >
    >
     
    tshad, Dec 2, 2005
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. tshad
    Replies:
    0
    Views:
    553
    tshad
    Apr 15, 2005
  2. Vikram

    disable checkbox list checkbox

    Vikram, Jan 25, 2006, in forum: ASP .Net
    Replies:
    1
    Views:
    1,414
    ThunderMusic
    Jan 25, 2006
  3. =?Utf-8?B?RG90TmV0RGV2?=

    DataGrid and embeded Checkbox..How to find if checkbox clicked

    =?Utf-8?B?RG90TmV0RGV2?=, Oct 6, 2006, in forum: ASP .Net
    Replies:
    1
    Views:
    849
    David Wier
    Oct 6, 2006
  4. oakura_ape

    Clientside CheckBox validation

    oakura_ape, Nov 2, 2006, in forum: ASP .Net
    Replies:
    1
    Views:
    478
    Onwuka Emeka
    Nov 2, 2006
  5. Jason Huang
    Replies:
    0
    Views:
    569
    Jason Huang
    Jun 29, 2007
Loading...

Share This Page