Link to home
Start Free TrialLog in
Avatar of Bulldog7
Bulldog7Flag for United States of America

asked on

Onclick to both disable and delete textbox data

I currently have a checkbox that will enable/disable a textbox, but only grays out the data if you click the box after. So after you hit Submit it is still there as a value. I would like to be able to, if you accidentally put text in the textfield and click on the checkbox it will both DELETE the text and make the field inactive. Is it possible with only one onclick?

<label for="txtBPSys">BP *</label></td>
			  <td width="187">
			  	<input size="3" type="text" id="txtBPSys" name="txtBPSys" maxlength="3" value="<%=.BPSys%>" /> / <input size="3" type="text" id="txtBPDia" name="txtBPDia" maxlength="3" value="<%=.BPDia%>" />
			  	<input type="checkbox" name="MyCheckboxBP"onclick="if(this.checked){txtBPSys.disabled=true;txtBPDia.disabled=true}else{txtBPSys.disabled=false;txtBPDia.disabled=false}"/>
				
				ND:<br /><br />			
				<label></label></td>
			</tr>

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of McNetic
McNetic
Flag of Germany image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Avatar of Albert Van Halen
Albert Van Halen
Flag of Netherlands image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Bulldog7

ASKER

Awesome guys, I only split it because you literally answered 2 mins. apart!
Quick question though...if I submit with text it refreshes with the same (GOOD), but if I click on the checkbox to indicate no data, when I refresh, the bozes are unchecked and the text is once again enabled.
Thoughts/suggestions?
That's something you can't do much about, it's dependent on the browsers behaviour. When reloading a page, the browser sends another request for the same page to the server, and the server can't know anything about the changes made to the form because it was not submitted. The browser 'could' in theory notice it is loading the same form and apply the changes you made after reloading, but I don't know of any browser behaving in such way. Usually, if you hit reload, it is because you want the form in the initial state.