DesiLogi Posted December 24, 2016 Report Share Posted December 24, 2016 I'm trying to use an if statement in js that references a data field to see if there's a null value. I can't get the syntax to work though. Here's the code in the footer of a Details datapage: <script> var v_lk = parseFloat(document.getElementById("EditRecordmstrSuppliers_LinkedIn").value); if(!(v_lk) === "") { document.getElementById('section3').style.display = "inline"; document.getElementById('section4').style.display = "none"; } else { document.getElementById('section3').style.display = "none"; document.getElementById('section4').style.display = "inline"; } </script> What's odd is I got this code to work using a test field that was a number format, using <script> var v_lk = parseFloat(document.getElementById("EditRecordmstrSuppliers_TestNumberfield").value); if(!isNaN(v_lk)) So it seems like I'm just not referencing the 'live' field correctly because it's a text field instead of a number field. Does anyone know the correct way to reference a text field to check for null/blank values? Quote Link to comment Share on other sites More sharing options...
TWIRED Posted December 25, 2016 Report Share Posted December 25, 2016 Hi , you could try this.. var x; if (x =='') or (x !=='') The element must not be hidden for it to work. you have to trick it var newone; newone = document.getElementById('InsertRecordCHKBOX'); if (newone == null) { newone=0 } Hope this helps. Thanks Quote Link to comment Share on other sites More sharing options...
TWIRED Posted December 25, 2016 Report Share Posted December 25, 2016 Heres an example that works, - to check a checkbox based on input from a non-hidden field or element. <script type="text/javascript"> var tagidvalue ; tagidvalue=document.getElementById('InsertRecordTagID').value; if (tagidvalue !=='') { document.getElementById('InsertRecordTagEmpRegisteredTagInSystem').checked=true; document.getElementById('InsertRecordTagEmpIsTagRegistrant').checked=true; } else if (tagidvalue =='') { document.getElementById('InsertRecordTagEmpRegisteredTagInSystem').checked=false; document.getElementById('InsertRecordTagEmpIsTagRegistrant').checked=false; } //alert (tagidvalue) </script> Quote Link to comment Share on other sites More sharing options...
TWIRED Posted December 25, 2016 Report Share Posted December 25, 2016 1 last thing.. when i used just else in the source / html footer could never get it to work. I dont know if its a bug. But when I used else if, it worked. Thanks Quote Link to comment Share on other sites More sharing options...
DesiLogi Posted December 25, 2016 Author Report Share Posted December 25, 2016 Hi TexterVaid, Thanks for the suggestion- I wasn't able to get it to work using that for some reason. I fiddled around and finally got the code to work- it seems Caspio is somewhat random as to what js works with its data fields. Removing the parseFloat, changing the if clause a bit (I tried 'else if' as suggested but just the 'else' ended up working) and making the fields 'hidden' seemed to get it right: var v_lk = document.getElementById("EditRecordmstrSuppliers_LinkedIn").value; if(!(v_lk) == "") { Thanks again for helping and hope this solution works for someone else too- TWIRED 1 Quote Link to comment Share on other sites More sharing options...
888Washington Posted November 7, 2017 Report Share Posted November 7, 2017 Hi, I'm trying to implement the code above to hide columns 7 and 8 in a tabular report if their values are null. I can't quite seem to tweak the code to make it work for me. See code below. I declared a variable called empqty, which should be the name of the field to check if there are values, if the data is empty (null) then the tabular report should hide columns 7 and 8. Any assistance would be greatly appreciated! Thank you! <script language="javascript" type="text/javascript"> var stl='none'; var tbl = document.getElementsByTagName('table')[0]; var rows = tbl.getElementsByTagName('tr'); var empqty = document.getElementById('Employee_Productivity_Qty'); If (empqty == null) { for (var row=1; row<rows.length;row++) { var cels = rows[row].getElementsByTagName('td'); cels[7].style.display=stl; cels[8].style.display=stl; } var heads= tbl.getElementsByTagName('th'); heads[7].style.display=stl; heads[8].style.display=stl; } </script> Quote Link to comment Share on other sites More sharing options...
Recommended Posts
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.