Jump to content
Sign in to follow this  
HSLBX15

Hide Field with Javascript

Recommended Posts

Hi all,

I'm trying to hide a field if there if no data is returned in the search results. For clarification it's a Details Datapage. I'm pretty sure this is really really simple for someone who knows javascript but I can't seem to piece together enough info from the other posts or the web to get it right.

This is what I have so far:

if("[@field:Address]"== "");

{

document.getElementById("[@field:Address]").style.display = "none";

}

Also, it's in an html block at the bottom of the datapage elements list.

Any help would be most appreciated!

Share this post


Link to post
Share on other sites

Thanks for that - I hadn't seen that post.

But unfortunately it still doesn't work. Below are 3 of the similar versions I've tried. Does it have to do with where I've located the html box? Or do I need to delete the original address field element?

var v= document.getElementById("[@EditRecordAddress]").value;

if (v = "")

{

document.getElementById("[@EditRecordAddress]".style.display = "none";

}

var v= document.getElementById('EditRecordAddress').value;

if (v = "")

{

document.getElementById('EditRecordAddress').style.display = "none";

}

var v= document.getElementById("[@EditRecordfield:Address]").value;

if (v = "")

{

document.getElementById("[@EditRecordfield:Address]".style.display = "none";

}

Many thanks

Share this post


Link to post
Share on other sites

I've now tried deleting the original address field, fixing the parenthesis in the last example, and moving it to a footer and none of those seem to work. (the later two were tried together).

Thanks,

Share this post


Link to post
Share on other sites

Hi!

Try them with double cuotes:

<script type= "text/javascript">
var v= document.getElementById("EditRecordAddress").value;
if (v == "")
{
document.getElementById("EditRecordAddress").style.display = "none";
}

</script>

Share this post


Link to post
Share on other sites

Two equal signs is the correct one. (==)

Also note that it works if your field is in the details page or an update form and it is editable. If the field is Display Only this code does not work.

By the way, Caspio's next version which is scheduled to be released by the end of October has a built-in feature to hide the field on details and results page if the value is blank. So no Java Scripting will be needed.

Best,

Bahar M.

Share this post


Link to post
Share on other sites

Great thanks very much for all your help. I've also found a less sophisticated way of accomplishing the same end with html and the field codes. But I will try these tips and I look forward to the new release in October.

Share this post


Link to post
Share on other sites

Hi all,

 

Hiding fields if empty doesn't need to have custom coding. This can be done using the standard feature of Caspio. On your DataPage > Configure Details Page Fields > Advanced

enable "Hide fields if blank". Please refer to the screenshot below:

image.png.7292e19d6c85b4c39f9b30eda27553c8.png

 

Regards,

kristina

 

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×