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: 

<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? 

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 ;

 

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>

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...

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>
 

 

 

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...