Jump to content

Check text field for null in javascript if then

Recommended Posts

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: 

   var v_lk = parseFloat(document.getElementById("EditRecordmstrSuppliers_LinkedIn").value);

if(!(v_lk) === "")
  document.getElementById('section3').style.display = "inline";
  document.getElementById('section4').style.display = "none";
  document.getElementById('section3').style.display = "none";
  document.getElementById('section4').style.display = "inline";

What's odd is I got this code to work using a test field that was a number format, using 

   var v_lk = parseFloat(document.getElementById("EditRecordmstrSuppliers_TestNumberfield").value);


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? 

Link to comment
Share on other sites

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 ;



if (tagidvalue !=='')








else if (tagidvalue =='')









//alert (tagidvalue)


Link to comment
Share on other sites

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- 

Link to comment
Share on other sites

  • 10 months later...


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');
var heads= tbl.getElementsByTagName('th');



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.

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.

  • Create New...