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
tgganeshtgganesh 

Pass field values to Java script function

Hi all,

 

I have created a VF Page.. I need to validate the values entering in a text box.

 

I should not enter more than three characters in that text box.

 

If i enter a value in text box, that value should pass to a java script function and that should validate and throw a error.

 

Please give me a sample code...

 

 

Starz26Starz26

***SEE Below***

tgganeshtgganesh

Hi Starz,

 

Thanks for your reply..

 

I tried like this and am not receiving anyting...

 

<apex:page standardController="Account" sidebar="false" >
<apex:form >
<script>
    function DisplayData(valu){
        alert(valu);
    }
</script>
<apex:outputPanel id="Nam">
<apex:inputField value="{!account.name}" id="message1" onblur="DisplayData(document.myForm.message1)"/>
</apex:outputPanel>
</apex:form>
</apex:page>

 please tell what mistake i have done.. and correct me if my code is wrong.. :(

 

 

 

Starz26Starz26

try this:

 

<apex:page standardController="Account" sidebar="false" >
<script>
function checkLimit(limitField, limitCount, limitNum)
{
    if (limitField.value.length > limitNum) {
        limitField.value = limitField.value.substring(0, limitNum);
    } else {
        limitCount.value = limitNum - limitField.value.length;
    }
}
</script>

<apex:form >

<apex:outputPanel id="Nam">
<apex:inputField value="{!account.name}" id="message1" onkeydown="checkLimit(this,this.form.Nam,3);"/>
</apex:outputPanel>
</apex:form>
</apex:page>

 

adapted from answer found HERE: http://boards.developerforce.com/t5/Apex-Code-Development/restrict-type-extra-characters-after-reaching-the-field-max/m-p/376531/highlight/true#M67164