Jump to content
  • 0

Can you hide an HTML block with a rule?


roattw

Question

I want to include an HTML reminder text on a form when a specific field on a form is a certain value.  Hint/Tip not what I want since its hidden unless licked.  I want some RED text to appear is form field = X.  I can get the text to display on form with HTML block.  But using Rule Conditions I cant choose to hide the HTML block, only actual fields.

Way to apply rule/condition to an HTML block?

Link to comment
Share on other sites

9 answers to this question

Recommended Posts

  • 1

I just came with another idea that should work, this is by using your current HTML block content.

  1. Create a section for these two elements, Specific LSN time: and your HTML block Message.
  2. Go to Rules in your Datapage and create a new Rule. If the radio is not equal to Specific, then hide the section that contains the field and the HTML Block

That would be pretty straight forward. You can learn more about this way in this article

Hope it helps.

Link to comment
Share on other sites

  • 1

Dear roattw,

Please replace your current HTML block for the following code:

<div id="msg24"></div>
<script>
var radioField = document.getElementsByName('InsertRecordLSN_time');
var messageCnt = document.getElementById('msg24');
function getRadioValue(){
	for (var i = 0, length = radioField.length; i < length; i++) {
		if (radioField[i].checked) {
			return radioField[i].value;
			break;
		}
	}
}

for (var i = 0, length = radioField.length; i < length; i++) {
	radioField[i].onchange = function(){
		if(getRadioValue() == 'Specific'){
			messageCnt.innerHTML = '<span class="cbInfoText">*24-hour clock</span>';
		} else {
			messageCnt.innerHTML = '';
		}
	}
}
</script>

Let us know whether or not it works.

Link to comment
Share on other sites

  • 0

Thanks Douvage

With my fledgling JS skills I have a question.  The example with showing/hiding images makes sense, but what is the function to show nothing?  Im my case if a field (LSN_time) contains the a specific radial button choice (Specific), then show HTML Block 2.  Other wise hide it.  This isnt working, presumably because of incorrect naming of the HTML Block.

 

<div id="LSNTime"></div>
<script>
var linkDiv = document.getElementById("LSNTime");
var  = 'HTML Block 2';

if('[@LSN_time]' == 'Specific'){
linkDiv.innerHTML = HTML Block 2;
} else {
linkDiv.innerHTML = none;
}
</script>

Link to comment
Share on other sites

  • 0

You are pretty close to get it. You may not be able to manipulate the HTML block from the Caspio Datapage, instead, your variable must contain the HTML code.

Let me give you a sample code:

<div id="LSNTime"></div>
<script>
var linkDiv = document.getElementById("LSNTime");
var content = '<p id="uniqueParagraph">This is the content that will show </p><a class="btn btn-success" href="#">Sample Link</a>';

if('FieldReference' == 'Specific'){
linkDiv.innerHTML = content;
}
</script>

Make sure you do good usage of single or double quotation marks. If you dont want to show anything, then the else statement is not needed.

Also, be careful when assigning the Field Reference, use the dropdown in the HTML block that contains all your fields to avoid typos.

Let us know whether or not you were able to accomplish it.

Link to comment
Share on other sites

  • 0

Thanks for the reply!  Probably not the best example as I dont need a button href link to cause anything.  I just need an HTML importan tnote field to appear (HTML block) is a value is selected.  The suggested code had an effect, it didnt show the red important note field at all so close.

Currently it looks like this.  *24-hour clock shows all the time (HTML block), need selective appearance.

LSN.jpg.603883edf7dc7e28bb8b1b2941933ce5.jpg

If  SPECIFIC selected here a field for "Specific LSN time" appears.  That's where we need the reminder to use 24 hour clock. Doesn't need to be there until then.:

Lsn2.jpg.5693f2446fd85d6ded31565cac01b342.jpg

The code had effect when placed in the HTML field, it prevented the block from appearing at all regardless of "Specific selection".

lsn1.jpg.4fc0877a7dea0390fad83957da1265a8.jpg

Lsn4.jpg.805f38d469664bf3a5b7871d50231b47.jpg

Still no Red Note HTML text.

Not sure if that HREF button or other call is needed to make run the change.  This one needs to just be on select.  In your example does the <P> ID uniqueParagraph need to to match of be noted somewhere else?

Lsn3.jpg

Link to comment
Share on other sites

  • 0

Wow.  Both work well.  Thank you!  The script version was very educational - I can see why it works and where mine was off.  The rule for hding the section is very elegant.  And proof that I tend to over think things.  I think this topic and solution will help other.  Thanks again.

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
Answer this question...

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