Java Script in Visualforce page

It is explaining how we are using the javascript invisual force.


<apex:page controller="javascriptec" id="mypage">
 <script>
 function clear()
 {

 }
 function myfunc()
 {
// alert("i am in function");
 var ks = document.getElementById("{!$Component.mypage.myform.myblock.mysection.item.fname}").value;
 var ln = document.getElementById("{!$Component.mypage.myform.myblock.lsec.litem.lname}").value;
 var ph = document.getElementById("{!$Component.mypage.myform.myblock.phones.phoneit.no}").value;
  var mal = document.getElementById("{!$Component.mypage.myform.myblock.mails.mailitem.mail}").value;
 
 count= ph.toString().length;
  if(ks=="" || ln == "")
{
alert("Please Enter Your Name");
}
 if(count<10 || count >10)
{
alert("Enter Valid Phone Number");
}
var phoneno = /^[0-9]+$/;
var maa= /^[a-zA-Z0-9._-]+@([a-zA-Z0-9.-]+\.)+[a-zA-Z0-9.-]{2,4}$/;
var s=!(ph.match(phoneno));
//alert(s);

  if(!(ph.match(phoneno)))
  {
  alert("Please give valid Number");
  }
  if(!(mal.match(maa)))
  {
  alert("enter valid email boss");
 
  }
  document.getElementById("mal").style["padding-top"] = "10px";
  // document.getElementById("mail").style.padding-top = "10px";
 // document.write("asgasdg");
 }
 </script>
 <!-- <c:mycomponent fstattri="agfasgasg" secondattri="green"/> -->
 <apex:form id="myform">
 <apex:messages />
 <apex:pageBlock id="myblock">
 <!-- <apex:pageBlockButtons >
      <apex:commandButton value="Save" />
   </apex:pageBlockButtons>-->
 <apex:pageBlockSection id="mysection">
 <apex:pageBlockSectionItem id="item">
 <apex:outputLabel >First Name</apex:outputLabel>
 <apex:inputText id="fname" />
 </apex:pageBlockSectionItem>
  </apex:pageBlockSection>
  <apex:pageBlockSection id="lsec" >
  <apex:pageBlockSectionItem id="litem" >
  <apex:outputLabel >Last Name</apex:outputLabel>
  <apex:inputText id="lname"/>
  </apex:pageBlockSectionItem>
   </apex:pageBlockSection>
  <apex:pageBlockSection id="phones">
  <apex:pageBlockSectionItem id="phoneit">
  <apex:outputLabel >Phone</apex:outputLabel>
  <apex:inputText id="no"/>
   </apex:pageBlockSectionItem>
   </apex:pageBlockSection>
     
  <apex:pageBlockSection id="mails">
  <apex:pageBlockSectionItem id="mailitem">
  <apex:outputLabel >Email</apex:outputLabel>
  <apex:inputText id="mail"/>
  </apex:pageBlockSectionItem>
   </apex:pageBlockSection>
   </apex:pageBlock>
 <apex:commandButton value="send" id="mybutton" onclick="myfunc()" reRender="myblock"/>
 <apex:commandButton onclick="this.form.reset();return false;" value="clear" reRender="myblock"/>
 </apex:form>
</apex:page> 

Comments

Popular posts from this blog

Community/Experience Cloud Interview Questions

Script to delete multiple records using Apex salesforce

Change Owner / Update record using Lightning Custom Button Salesforce