Jump to content
Niranjan

Js Validations Not Working Consistently

Recommended Posts

I am working with Submissions, Single Record Update and Details pages, where I understand the following script (and it's variants) should work. However the behaviour is not consistent. 

 

A) The following works just fine (helps ensure unique "Tag Name" within same "Project":

 

<SCRIPT LANGUAGE="JavaScript">

function concatenate()
{
var TagName = document.getElementById("InsertRecordTagName").value;
var ProjectID = document.getElementById("InsertRecordProjectID").value;
var ChkUnique = TagName + ProjectID;
document.getElementById("InsertRecordChkUnique").value = ChkUnique;
}
document.getElementById("caspioform").onsubmit=concatenate;
</SCRIPT>
 
B) However the following, in another page but with pretty much the same logic (need to ensure unique PermittedUserEmail for given project), doesn't work (there is no value inserted into the ChkUnique field in the database, unlike the first case)
 
<SCRIPT LANGUAGE="JavaScript">
function concatenate()
{
var PermittedUserEmail = document.getElementById("InsertRecordPermittedUserEmail").value;
var ProjectID = document.getElementById("InsertRecordProjectID").value;
var ChkUnique = PermittedUserEmail + ProjectID;
document.getElementById("InsertRecordChkUnique").value = ChkUnique;
}
document.getElementById("caspioform").onsubmit=concatenate;
</SCRIPT>
 
C) Also, the following, though a different context and logic, doesn't work either: (This is a Details page so I understand InsertRecord needs to change to EditRecord)
 
<script>
function chk_date(){
var startdate = document.getElementById("EditRecordStartDate").value;
var enddate = document.getElementById("EditRecordEndDate").value;
if ( Date.parse(startdate) <  Date.parse(enddate) ) {
alert('Start Date must be less or equal to than End Date');
return false;
}
}
document.getElementById("caspioform").onsubmit=chk_date;
</script>

Share this post


Link to post
Share on other sites

Hi Niranjan,

 

In B Script, is the "PermittedUserEmail" field checkbox?

If yes, I am not sure that understand the logic of the script.

 

In C Script, are "StartDate" and "End Date" editable fields?

They must be editable, then, I hope, the Script will work.

Share this post


Link to post
Share on other sites

Hello Jan

 

The PermittedUserEmail field is text, just like the Tag Name field in Script A, so I was expecting it to work in exactly the same way. They are also both drop-downs, and not free text, not that that should matter but anyway what I mean is the scripts are the same in every way except for field names and the page on which they occur, yet one works and the other doesn't!

 

On Dates, yes they are both editable, yet it is not working. 

 

Thanks for looking into it!

 

Best regards

Share this post


Link to post
Share on other sites

Hi Jan

 

The Email field is a cascade DD. I read up on the Dynamic link you sent, thanks for that. To explore if this is the issue, I tried changing the concatenation to another field in the same table (not a cascade DD but just a normal Drop down) and I still have the same issue. 

 

I can send you the URL but how would that help? You would need to access it only via the app, without which on-load parameters and all that won't work. And using this feature via the app will need some context in what the app is doing. I am more than happy to provide that but I suppose that will soak up time on your part that you may not have :-) 

 

By the way thanks for pointing out the silly mistake in the date check !!!! Has to be the oldest mistake in the programmer's book? 

 

Best regards

Share this post


Link to post
Share on other sites

Hi Niranjan,

 

Sometimes it is enough to see the code of the page, and if I have the URL, I can see the code with the "Inspect element" feature of browsers. Maybe, I will be able to find what is wrong.

 

And I hope I will have free time to investigate your page :)

Share this post


Link to post
Share on other sites

Hey Jan

 

Ok here goes; The first URL is for a form that works fine (that is, stops entry of duplicates by concatenating two fields and trying to enter the result into a 3rd field which is set  to "unique" at data base level. The second URL doesn't work even though it has the same structure. I have removed the "unique" flag in the database for that one, so as to see if it sets any value at all, and I keep seeing blanks there. 

 

URL for page that works:

 

http://c0ect399.caspio.com/dp.asp?AppKey=c22e3000371b2d8e8ac641b0b5cc

 

URL for page that doesn't work:

 

http://c0ect399.caspio.com/dp.asp?AppKey=c22e3000d167695596a349d78fd6

 

 

Hope this helps and thanks again!

 

Niranjan

Share this post


Link to post
Share on other sites
Hi Niranjan,

 

The first element is dynamic, if I understand correctly. So you can change

 

var PermittedUserEmail = document.getElementById("InsertRecordPermittedUserEmail").value;

to

var PermittedUserEmail = document.getElementsByName("InsertRecordPermittedUserEmail")[0].value;

 

Then the whole script will be like:



<SCRIPT LANGUAGE="JavaScript">
function concatenate()
{
var PermittedUserEmail = document.getElementsByName("InsertRecordPermittedUserEmail")[0].value;
var ProjectID = document.getElementById("InsertRecordProjectID").value;
var ChkUnique = PermittedUserEmail + ProjectID;
document.getElementById("InsertRecordChkUnique").value = ChkUnique;
}
document.getElementById("caspioform").onsubmit=concatenate;
</SCRIPT>


I hope, it works :)

Share this post


Link to post
Share on other sites

Hi Jan, I tried but to no avail. Interestingly, I did the following, and the alert did not fire at all suggesting the on submit call is not firing for some reason at all. I also put both ways of accessing the value, just in case, but like I said no alerts came to the screen.

 

<SCRIPT LANGUAGE="JavaScript">

 
function concatenate()
{
var PermittedUserEmail = document.getElementByName("InsertRecordPermittedUserEmail")[0].value;
var oldstyleemail = document.getElementByID("InsertRecordPermittedUserEmail").value;
var ProjectID = document.getElementById("InsertRecordProjectID").value;
 
var ChkUnique = PermittedUserEmail + ProjectID;
 
 
document.getElementById("InsertRecordChkUnique").value = ChkUnique;
 
 
alert(PermittedUserEmail);
alert(oldstyleemail);
alert(ProjectID);
alert(ChkUnique);
}
 
document.getElementById("caspioform").onsubmit=concatenate;
</SCRIPT>

Share this post


Link to post
Share on other sites

Hi Niranjan,

 

If I understand correctly, the following line brakes the code:

var oldstyleemail = document.getElementByID("InsertRecordPermittedUserEmail").value;

 

JavaScript cannot find the "InsertRecordPermittedUserEmail" object and stops. If you display alerts after every line, like

 

var PermittedUserEmail = document.getElementByName("InsertRecordPermittedUserEmail")[0].value;
alert(PermittedUserEmail);
var oldstyleemail = document.getElementByID("InsertRecordPermittedUserEmail").value;
alert(oldstyleemail);
var ProjectID = document.getElementById("InsertRecordProjectID").value;

alert(ProjectID);

 

You see, that only the first variable is displayed.

 

I think so :)

Share this post


Link to post
Share on other sites

Hi Jan

 

Just tried that too, put alerts after each statement and also tried with both the old style email in the code as well as completely removed, and still got no alerts at all. Then I tried just a "I am here" alert in the script before any other statement and that worked! Which means the script is firing, but actually neither method of extracting the email is working. I tested with just Project ID and that worked fine, of course it does not achieve the purpose of the whole step. 

 

So basically I am unable to extract the email field by either method and JS just stops there without error messages. 

 

Thanks for persisting with my problem!

 

Best regards

 

Niranjan

Share this post


Link to post
Share on other sites

Hi Jan

 

I have found the issue (yay!), certainly this particular page is fixed now and I will use this to address all other instances and hopefully not come across a new problem.

 

Not surprisingly it was a silly coding error! When I changed from getElementByID to getElementByNames[0], I had forgotten that in the syntax of getting "by name", the word "name" is plural which is different from "ID" which is in singular. So my code was saying getElementByName instead of getElementByNames. !!!!

 

Regards

 

Niranjan

Share this post


Link to post
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...