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
Rosy09Rosy09 

How to check the password Validation.

Hi..

 

Am trying for password validation using javascript in apex class.But i dont know where i went wrong .Can anyone please go through the below  code and let me know my mistake.

 

Thanks in advance.

 

<apex:page controller="pwdvaldcon">
<script>
function validate(){

var myTextField = document.getElementById('pp');
if(myTextField.value != "")
alert("You entered: " + myTextField.value)
else
alert("Would you please enter some text?")
}
</script>

<apex:form id="frm">
<apex:pageBlock id="pg">
<apex:pageBlockSection id="pbs">
<apex:inputText value="{!name}" label="Name" id="pn"/>
<apex:inputText value="{!pwd}" label="password" id="pp"/>
<apex:commandButton value="save" action="{!save}"/>
</apex:pageBlockSection>
</apex:pageBlock>
</apex:form>

</apex:page>

     

Controller:

 

   

public with sharing class pwdvaldcon {

public String name { get; set; }
public String pwd { get; set; }
public new_account__c na {get;set;}



public pwdvaldcon(){
na = new new_account__c();

}
public PageReference save() {
na.password__c = pwd;
na.name=name;

insert na ;
return null;
}

}

KodiKodi

Hi,

 

can u try this below code,

 

<apex:page controller="pwdvaldcon" id="pg1">
<apex:form id="frm">
<apex:pageBlock id="pbk">
<apex:pageBlockSection id="pbs">
<apex:inputText value="{!name}" label="Name" id="pn"/>
<apex:inputText value="{!pwd}" label="password" id="pp"/>
<apex:commandButton value="save" action="{!save}" onclick="validate();"/>
</apex:pageBlockSection>
</apex:pageBlock>
</apex:form>
</apex:page>

<script>
function validate()
{
var myname=document.getElementById("{!$Component.pg1.frm.pbk.pbs.pn}").value;
var mypwd=document.getElementById("{!$Component.pg1.frm.pbk.pbs.pp}").value;
if(mypwd!=null)
{
alert("You Entered"+myname);
}
else
{
alert("Would you please enter some text?");
}
</script>

Rosy09Rosy09
Hi...kodi

Tnq for ur reply..wil try tat code.