Results 1 to 7 of 7
  1. #1
    Join Date
    Jul 2002
    Posts
    11

    Urgent ! How to Enable a text field only on selecting a radio button in JSP

    Hello -
    I want to create a radio button and next to it are two text fields. Only on select that radio button, the two text fields should get enabled. How to do this? Thanks. Edwk

  2. #2
    Join Date
    Jan 2003
    Location
    de/ro
    Posts
    12

    perhaps this can help

    This is a JavaScript and I don't understand why do you want to code it in JSP!

    The function enableText is triggered at onClick on the radio button.
    it checks if exists any enabled text fields and disable them and then enables the required fields, specified by the elementId.

    Here it is:

    <!doctype html public "-//W3C//DTD HTML 4.0 Transitional//EN">
    <html>
    <head>
    <title> New Document </title>
    <script language="JavaScript">
    <!--
    var currentFields = "";

    function enableText(elementId){
    if (currentFields != "") {
    eval("document.forms[0].text_" + currentFields + "_a.disabled=true;");
    eval("document.forms[0].text_" + currentFields + "_b.disabled=true;");
    }
    eval("status = document.forms[0].text_" + elementId + "_a.disabled");
    if (String(status) == String("true")) {
    eval("document.forms[0].text_" + elementId + "_a.disabled=false;");
    eval("document.forms[0].text_" + elementId + "_b.disabled=false;");
    }
    currentFields = elementId;
    }
    //-->
    </script>
    </head>

    <body bgcolor="#FFFFFF">
    <form name="oneForm" method="post" action="">
    <input type="radio" name="radioButton" onclick="javascript:enableText('1');"><input type="text" name="text_1_a" disabled><input type="text" name="text_1_b" disabled>
    <br>
    <input type="radio" name="radioButton" onclick="javascript:enableText('2');"><input type="text" name="text_2_a" disabled><input type="text" name="text_2_b" disabled>
    </form>
    </body>
    </html>
    Last edited by wakhy; 01-03-03 at 05:40.

  3. #3
    Join Date
    Jan 2003
    Location
    KC, MO
    Posts
    7
    definelty go w/ the javascript ... but doesnt work w/ Netscape so be aware.

  4. #4
    Join Date
    Jan 2003
    Location
    de/ro
    Posts
    12

    Exclamation it works with mozilla&co.

    There was a mistake when I submitted the script, the "javascript" statement from the onclick event was transformed in "java script" by the forum parser.
    So if you change the "java script:" fron the onclick event handler from the <input type="radio" then it will work on mozilla & co.

    sorry ... but the forum parser is kind of strange! .....

    I tried to resubmit the code in the proper way, but there is no chance that I could bypass the parser.... so please do the above changes in the code manually.

    Last edited by wakhy; 01-06-03 at 17:54.

  5. #5
    Join Date
    Jan 2003
    Location
    KC, MO
    Posts
    7
    i didnt think that

    document.form1.field.disabled = true worked in NS 4.7

    my bad i guess i was thinking wrong

  6. #6
    Join Date
    Jan 2003
    Location
    KC, MO
    Posts
    7
    Yeah I just tried it out it will work in NS 7 but not NS 4.7 so it's your call on if you want to do it that way. A nice little trick to disabling form elements in NS 4.7 is just putting:

    onFocus="blur();"

    in the form elements tag. That way as soon as a user clicks on it, they will be kicked from the focus.

  7. #7
    Join Date
    Jan 2003
    Location
    de/ro
    Posts
    12
    Originally posted by ghw0668
    Yeah I just tried it out it will work in NS 7 but not NS 4.7 so it's your call on if you want to do it that way. A nice little trick to disabling form elements in NS 4.7 is just putting:

    onFocus="blur();"

    in the form elements tag. That way as soon as a user clicks on it, they will be kicked from the focus.

    yes, but is kind of annoying ... for a user... bad usability ....

Posting Permissions

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