Results 1 to 2 of 2

Thread: Disable a field based on another field's value

  1. #1
    Join Date
    Nov 2009
    Posts
    12

    Default Disable a field based on another field's value

    I am attempting to disable a textfield based on the choice of 3 radio buttons. Though, I am completely unable to run any "onclick" script from these radio buttons. I can assume I am simply missing something or even simpler, don't know what's going on. Below is a rough draft snippet of the code I'm trying to produce. I apologize I am not able to clean it better. Any advice?



    <script type="text/javascript">
    function disableTextbox()
    {
    alert('Clicked a security level....');
    //if(document.getElementById('secureLevel').checked == true)
    {
    //document.getElementById("securityTextbox").readonl y = true;
    //alert('True');
    }
    //else
    {
    //document.getElementById("securityTextbox").readonl y = false;
    //alert('False');
    }
    }
    </script>

    <form:radiobutton id="clearLevel" path="security" label="Clear" value="clearLevel" onclick="alert('hello');"/>
    <form:radiobutton id="secureLevel" path="security" label="Secure" value="secureLevel" onclick="disableTextbox();"/>
    <form:radiobutton id="bothLevel" path="security" label="Both" value="bothLevel" onclick="disableTextbox();"/>

    <script type="text/javascript">
    Spring.addDecoration(new Spring.ElementDecoration({
    elementId : 'clearLevel',
    widgetType : "dijit.form.RadioButton",
    widgetModule : "dijit.form.CheckBox",
    widgetAttrs : {promptMessage: "Clear"}
    }));
    Spring.addDecoration(new Spring.ElementDecoration({
    elementId : 'secureLevel',
    widgetType : "dijit.form.RadioButton",
    widgetModule : "dijit.form.CheckBox",
    widgetAttrs : {promptMessage: "Secure"}
    }));
    Spring.addDecoration(new Spring.ElementDecoration({
    elementId : 'bothLevel',
    widgetType : "dijit.form.RadioButton",
    widgetModule : "dijit.form.CheckBox",
    //onclick : disableTextbox(),
    widgetAttrs : {promptMessage: "Both"}
    }));
    </script>
    </td>
    </tr>
    <tr>
    <td class="tdLabel">
    Security Textbox:
    </td>
    <td>
    <form:input id="securityTextbox" path=""/>
    <script type="text/javascript">
    Spring.addDecoration(new Spring.ElementDecoration({
    elementId : "securityTextbox",
    widgetType : "dijit.form.ValidationTextBox",
    widgetAttrs : {promptMessage: "Security Text Box"}
    }));
    </script>
    </td>
    </tr>

  2. #2
    Join Date
    Nov 2009
    Posts
    12

    Default

    For anyone looking at this message, I believe I found out a way to use an "onclick" option going around the Spring.addDecoration() method. Being new to Spring I still do not fully understand whether or not that spring method has the capability to execute an "onclick"-esqe operation. That being said I stumbled on a workaround by placing a link under the decoration (I believe I've said that correctly). To get a better idea of what I'm talking about, I have a code snippet below. The radio buttons disable the text field if the "secure" button is selected based on a script in simple JS code. Since I didn't get an answer I figured I would post the one I found just in case someone else comes across this sort of problem.


    ...............

    <td class="tdLabel">
    Security Level:
    </td>
    <td>
    <script type="text/javascript">
    function securityButton()
    {
    if(document.getElementById('secureLevel').checked == true)
    {
    document.getElementById("securityTextbox").disable d = true;
    }
    else
    {
    document.getElementById("securityTextbox").disable d = false;
    }
    }
    </script>
    <a href="securelevel" onclick="securityButton();">
    <form:radiobutton id="clearLevel" path="security" label="Clear" value="clearLevel"/>
    <form:radiobutton id="secureLevel" path="security" label="Secure" value="secureLevel"/>
    <form:radiobutton id="bothLevel" path="security" label="Both" value="bothLevel"/>
    </a>
    <script type="text/javascript">
    Spring.addDecoration(new Spring.ElementDecoration({
    elementId : 'clearLevel',
    widgetType : "dijit.form.RadioButton",
    widgetModule : "dijit.form.CheckBox",
    widgetAttrs : {promptMessage: "Clear"}
    }));
    Spring.addDecoration(new Spring.ElementDecoration({
    elementId : 'secureLevel',
    widgetType : "dijit.form.RadioButton",
    widgetModule : "dijit.form.CheckBox",
    widgetAttrs : {promptMessage: "Secure"}
    }));
    Spring.addDecoration(new Spring.ElementDecoration({
    elementId : 'bothLevel',
    widgetType : "dijit.form.RadioButton",
    widgetModule : "dijit.form.CheckBox",
    widgetAttrs : {promptMessage: "Both"}
    }));
    </script>
    </td>
    </tr>
    <tr>
    <td class="tdLabel">
    Security Textbox:
    </td>
    <td>
    <form:input id="securityTextbox" path="security"/>
    <script type="text/javascript">
    Spring.addDecoration(new Spring.ElementDecoration({
    elementId : "securityTextbox",
    widgetType : "dijit.form.ValidationTextBox",
    widgetAttrs : {promptMessage: "Security Text Box"}
    }));
    </script>
    </td>
    </tr>
    </table>
    </form:form>
    </body>
    </html>
    Last edited by mrt2100; Dec 1st, 2009 at 11:29 AM.

Posting Permissions

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