Javascript HELP???

Results 1 to 3 of 3

Thread: Javascript HELP???

  1. #1
    xin Guest

    Default Javascript HELP???

    In my form, I have a radio button with "Yes" and "No" options. Based on the radio button I check, I want to write a javascript which will enable/disable another input text box.<BR><BR>My javascript :<BR><BR>function RadValid() {<BR> if (formname.RadButton.value = "Yes") {<BR> formname.txtbox.disabled = true;<BR> }<BR> else {<BR> formname.txtbox.disabled = false;<BR> }<BR>}<BR><BR>HTML :<BR><BR>&#060;input TYPE="radio" NAME="RadButton" VALUE="Yes" onClick="Radvalid(this);"&#062;Yes<BR>&#060;input TYPE="radio" NAME="RadButton" VALUE="No" onClick="Radvalid(this);" CHECKED&#062;No<BR><BR>When I run this code, on clicking "yes" I&#039;m unable to write into the txtbox however the txtbox doesn&#039;t get dimmed. How can I acheive that? Also on clicking back "No", I&#039;m still unable to write into txtbox. Can anyone help me detect where in this code I&#039;m going wrong?<BR>

  2. #2
    Join Date
    Dec 1969

    Default The classic C/C++/Java/JS mistake...

    if (formname.RadButton.value = "Yes") <BR><BR> you *really* want to *always* set the value of the radio button to "Yes"? Because that is what you are doing.<BR><BR>Don&#039;t you want to use == to do a comparison, instead of an assignment?<BR><BR>ALSO...<BR><BR>(1) The .disabled property is available *ONLY* in MSIE. It does exactly nothing in other browsers. So maybe you should find another way to do this? Such as using the onFocus event of the field to deflect the focus if you want the field disabled.<BR><BR>(2) Disabling a form field does *not* imply a change in background color. Use a Style and change it to achieve this.<BR><BR>

  3. #3
    Join Date
    Dec 1969

    Default RE: Javascript HELP???

    &nbsp;<BR>Well, a couple of things. First off, "disabled" is only supported by IE, so this won&#039;t work in Netscape no matter what. Consequently, my answer is in two parts:<BR><BR>IE: In your onClick, I notice you have no internal capitalization in "Radvalid" and you include the "this" argument. This is different from your function. Change it to "RadValid()". Also, add "document." before "formname" everywhere it appears in the function. That&#039;s how I got it to work in IE.<BR><BR>NN: If you want this to work in Netscape, you had best set up a function where, when enabled by clicking "Yes", you blur the textbox everytime someone focuses on it. You can find code like this here:<BR><BR><BR>Botch<BR><BR><BR>

Posting Permissions

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