0

OnKeypress is not working when i click on input type field its not showing inputtextarea.

<input type="Text" onKeyPress="myFunction()" styleClass="slds-input" value="enter email" id="intag"/>

 <apex:inputTextarea cols="100" rows="10"  id="textareaMsg" value=" {!msgbody}"/>

 <script>
    function myFunction() {
      document.getElementById('textareaMsg').show();
     }
</script>
1
  • you need to specify entire component path if you use document.getElementById – Santanu Boral May 14 '18 at 7:13
1

This might help. This worked for me >

    <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
    <input type="Text" onKeyPress="myFunction()" styleClass="slds-input" value="enter email" id="intag"/>

<apex:inputTextarea cols="100" rows="10"  id="textareaMsg" value="{!msgbody}" style="display:none" styleClass="testtextarea" />

 <script>
 function myFunction() {
  alert('key press working');
  $(".testtextarea").show();
}
</script>
3
  • only alert message is showing not the textarea – cloudZigZag May 14 '18 at 7:56
  • @cloudZigZag, have you added the script above, it is jquery which must be added to make it work! – Saumya Gaikwad May 14 '18 at 11:25
  • yes added directly and in static resource as well. – cloudZigZag May 14 '18 at 11:35
0

The onkeypress event occurs when the user presses a key (on the keyboard). In your case use onclick event. Use style.display = 'block' instead of show(). Javascript querySelector is more recommend than jquery $.

<apex:page>
    <script>
        function myFunction() {
            debugger;
            document.querySelector("[id*='textareaMsg']").style.display='block';
        }
    </script>
    <apex:form>
        <input type="Text" onClick="myFunction()" value="enter email" id="intag"/>

        <apex:inputTextarea cols="100" rows="10"  style="display:none"  id="textareaMsg"/>
    </apex:form>
</apex:page>

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.