Using JScript to disable textbox according to valu

Results 1 to 2 of 2

Thread: Using JScript to disable textbox according to valu

  1. #1
    Join Date
    Dec 1969

    Default Using JScript to disable textbox according to valu

    I have a simple task that I can&#039;t get to work correctly.<BR><BR>I want to use a checkbox to enable or disable a text field.<BR>If user clicks the checkbox(checked=True) then disable the textbox...if the user clicks the checkbox(checked=False) then set value of textbox = "" and enable textbox.<BR><BR>I have attempted two functions (neither work consistently):<BR><BR>function tField() {<BR> if (document.forms[0].chkDays.checked) {<BR> document.forms[0].txtBackChargeWhy.value = ""; <BR> document.forms[0].txtBackChargeWhy.disabled;<BR> } <BR> else {<BR> document.forms[0].txtBackChargeWhy.disabled = false;<BR> } <BR>}<BR><BR> AND ALSO TRIED:<BR><BR>function toggleField(textObj) {<BR> var field = textObj.value;<BR> if (field = "on") {<BR> document.VariancePO.txtBackChargeWhy.disabled = true; <BR> }<BR> else{<BR> document.VariancePO.txtBackChargeWhy.disabled = false; <BR> }<BR>}<BR><BR>I am using a onblur event on the checkbox to trigger the function:<BR>&#060;INPUT TYPE="CHECKBOX" NAME="chkDays" CHECKED onBlur="javascript:tField()"&#062;Yes<BR><BR>Any suggestions?<BR><BR>TIA<BR>Keith

  2. #2
    heaven's martini Guest

    Default javascript method

    hmm<BR><BR>well what i do is this.<BR><BR>have a function that returns false if the checkbox is not checked (denoting no textbox entry).<BR><BR>in the textbox, i use the onFocus=if(!myfunction()){this.blur();}<BR><BR>i have used this and its simple and works. good luck

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts