Jump to content

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!

Link to comment
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

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

Link to comment
Share on other sites

  • 7 years later...

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

 

Link to comment
Share on other sites

  • 2 months later...
  • 1 year later...

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