Advertisement
f1lam3ntx0

JS Remoting Code

Feb 11th, 2021
771
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
HTML 2.58 KB | None | 0 0
  1. <apex:page docType="html-5.0" controller="JavascriptRemotingController">
  2.  
  3.     <head>
  4.  
  5.     </head>
  6.  
  7.     <body id="bd">
  8.         <div id="div">
  9.             First Name :
  10.             <input type="text" name="fname" id="firstname"></input>
  11.             <br></br>
  12.             Last Name:
  13.             <input type="text" name="lname" id="lastname"> </input>
  14.             <br></br>
  15.             Email:
  16.             <input type="text" name="eml" id="email"></input>
  17.             <br></br>
  18.             <button onclick="creatRecord">Submit</button>
  19.  
  20.         </div>
  21.     </body>
  22.     <script type="text/javascript">
  23.         function fnameFunc() {
  24.             // This Javascript is to test the field visibility checkboxes.
  25.             var fieldLevelSecurityCheck = document.querySelectorAll(".displayCol input");
  26.             for (var i = 0; i < fieldLevelSecurityCheck.length; i++) {
  27.                fieldLevelSecurityCheck[i].checked = "checked";
  28.            }
  29.            //here we are getting all the values fo the input data.
  30.            var fname = document.getElementById('firstname').value;
  31.            var lname = document.getElementById('lastname').value;
  32.            var email = document.getElementById('eml').value;
  33.            //checking if uses tries to submit without filling out the field
  34.            if (fname.length < 1 || lnmae.length < 1 || email.length < 1)
  35.                alert('Please Enter your Missing Details ');
  36.            else {
  37.                JavascriptRemoting.createRecord(fname, lname, email
  38.                function (result, event))
  39.                {  //event.status ensure that we are getting all the data in correct ajax form or not if not the status will be false and nothing will proceed further.
  40.                    if (event.status) {
  41.                        //This is the way to get VF tag id to map the result returned from call back function parameter result
  42.                        document.getElementById("{!$Component.bd.div.firstname}").innerHTML = result;
  43.                        document.getElementById("{!$Component.bd.div.lastname}").innerHTML = result;
  44.                        document.getElementById("{!$Component.bd.div.eml}").innerHTML = result;
  45.                    }
  46.                    // checking for the exception if out data have been recieved from remoting
  47.                    else if (result.type === 'exception') {
  48.                        alert("Exception caught");
  49.                        else (
  50.                            alert("Exception caught");
  51.                    }
  52.                };
  53.  
  54.            }
  55.        }
  56.    </script>
  57. </apex:page>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement