Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

checkbox disabled but need the value 1

Status
Not open for further replies.

dkemas

Programmer
Mar 22, 2012
70
GB
A have a form that contains several fields, one of these is a dropdown with three options (3,2,1) and a checkbox. I am using javascript to tick the checkbox if the value '1' is selected in the dropdown

Code:
document.myform.redflag.checked = (control.value=="1")? true : false;

This works fine. HOWEVER

I need to show the checkbox on the website but not allow the value to be changed. To do this I am using 'disabled' in my input html

Code:
<input type='checkbox' value='1' disabled />

When '1' is selected in the dropdown the checkbox is ticked and the checkbox is greyed out preventing the user form changing the value, BUT when I submit the form the value of '1' isn't being passed. If I remove 'disabled' the value gets passed without a problem.

Can I have the checkbox disabled but the avlue to be sent on submit of the form?

Thanks
 
Hi

If you want to have it submitted, do not make it [tt]disabled[/tt]. If you want to disallow changing its value make it [tt]readonly[/tt].

Note that an equality check evaluates to boolean. So [tt]control[teal].[/teal]value[teal]==[/teal][green]"1"[/green][/tt]'s value is already [tt]true[/tt] or [tt]false[/tt], so no need to use ternary operator :
Code:
document[teal].[/teal]myform[teal].[/teal]redflag[teal].[/teal]checked [teal]=[/teal] control[teal].[/teal]value[teal]==[/teal][green][i]"1"[/i][/green][teal];[/teal]

Feherke.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top