Jump to content

Javascript validation not working


Recommended Posts

Hello,

I am just starting with Javascript, (I do program in other languages). I am trying to capture the situation where a user does not enter either a Primary or Secondary phone.  This is on a Submission page. I inspected the items and it had EditRecordPrimaryPhone on the page .I also tried InsertRecord, but nothing works. It doesn't look like the page is running the Javascript at all, and I don't know how to debug it. I added a message that I hoped I would see either way to try to check that the Javascript was running. I put the code in the Footer.  Are there ways of debugging?  

Thanks

Tonie

<SCRIPT LANGUAGE="JavaScript">

function checkPhones(){

var p1 = document.getElementById("EditRecordPrimaryPhone").value;
var p2 = document.getElementById("EditRecordSecondaryPhone").value;

if(p1 == "" && p2 == ""){
  {
    window.alert('Please input at least one phone number');
    return false;
  }
else
  {
    window.alert( p1 + '' + p2);
    return false;
  }
 }

}

document.getElementById("caspioform").onsubmit=checkPhones;

</SCRIPT>

Link to comment
Share on other sites

Hi @Tonie,

 

If you were using a Submission Form, you must use 'InsertRecord' prefix instead of 'EditRecord'. Also, please check if the Ajax loading is enabled. You must disable it first to make your JavaScript to work.

image.png.c328cf5e447c59e4a22f8d2ddc1b91ad.png

I tried this code on my end and it works as expected.

<SCRIPT LANGUAGE="JavaScript">

 function check()
 {
   var p1 = document.getElementById("InsertRecordPrimaryPhone").value;
   var p2 = document.getElementById("InsertRecordSecondaryPhone").value;
   
if(p1 == '' & p2 == '') {
    window.alert('Please input at least one phone number');
    return false;
}

else {      
     window.alert(p1+' ' + p2);
}
}

 document.getElementById("caspioform").onsubmit=check;

</SCRIPT>

 

Hope this helps! 

Link to comment
Share on other sites

Thank you!!!!!

I had no idea about the Ajax loading. What does that do?

It works now for my submission form. The code I copied was from my update form, so I am hoping it will work there with the EditRecord .

Are there any other tricks am I missing to get Javascript to work? 

Thank you again

Link to comment
Share on other sites

AJAX is a capability that allows immediate communication between Caspio’s servers and deployed DataPages, so users can easily interact with applications without reloading the entire web page. AJAX loading provides a superior user experience and performance of common interactions such as data submission, sorting, paging and refreshing results pages with new criteria.

For applications with multiple DataPages deployed on the same web page, the data will automatically refresh across all DataPages when users interact with the application.

To know more, please refer to https://howto.caspio.com/datapages/ajax-loading/.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...