function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
karthikeya 2karthikeya 2 

How to enable and disable input text using javascript ?

Hi All,
can any one help me by giving code for vfpage
1) should contain stndard controller and extension
2) one input text and command Button
on loading page the textbox should be disable and when button is clicked it should get enabled. by using javascript.

please can any one give code for this.
 
ManojjenaManojjena
Hi Karthikeya,

Please try with below code it will help.
<apex:page standardController="Account" extensions="DemoExtension" id="pg">
     <apex:form id="frm">
         <apex:inputText value="{!demoText}" label="EnterText" id="intxt" disabled="true"/>
         <apex:commandButton action="{!doAction}" id="cmdbtn" onclick=" return doEnable();" value="Click" reRender="frm"/>
     </apex:form>
     <script>
        function doEnable(){
           document.getElementById("pg:frm:intxt").disabled='';
        }
     </script>
</apex:page>

public class DemoExtension {
    public String demoText{get;set;}
    public DemoExtension (ApexPages.StandardController con){}
    public void doAction(){}
}

 
karthikeya 2karthikeya 2
Can you give the same code by using jQuery please.
ManojjenaManojjena
Ok Karthikeya,

You can try with below page code which is implemented with JQuery .

One thing some times the JQuery librery will not available in web .So better you can download the Librery and add in static resource .
 
<apex:page standardController="Account" extensions="DemoExtension" id="pg">
    <head>
		<script src="//code.jquery.com/jquery-1.10.2.js"></script>
		<script src="//code.jquery.com/ui/1.11.4/jquery-ui.js"></script>
		<link rel="stylesheet" href="/resources/demos/style.css" />
		<link rel="stylesheet" href="//code.jquery.com/ui/1.11.4/themes/smoothness/jquery-ui.css" />
   </head>
     <apex:form id="frm">
         <apex:inputText value="{!demoText}" label="EnterText" id="intxt" disabled="true" styleClass="txt"/>
         <apex:commandButton action="{!doAction}" id="cmdbtn" onclick=" return doEnable();" value="Click" reRender="frm" />
     </apex:form>
        <script>
           function doEnable(){
             $(".txt").prop("disabled",false);
          }
        </script>
</apex:page>

Here I have given one example how to add librery in static resource .
<script src="{!URLFOR($Resource.JQuery19UI, '/jquery-ui-1.9.2.custom/js/jquery-1.8.3.js')}"/>
<script src="{!URLFOR($Resource.JQuery19UI, '/jquery-ui-1.9.2.custom/js/jquery-ui-1.9.2.custom.min.js')}"/>
Here my static resource name is JQuery19UI.I have changed the code as static resource will not avialble for you .

You can download the Librery from below link .

http://jqueryui.com/download/


Don't forget to select as best answer if it helps to solve your problem .
 
Rajesh Rajesh KumarRajesh Rajesh Kumar
Hii
if picklist value rating - 'hot' ( button should be enable or user can click) if rating other than warm button should or disable.