Setting Checkbox clientside

T

tshad

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
 
C

CK

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

Hope this helps.
CK
 
T

tshad

CK said:
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
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,483
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top