jquery & CEWP to hide fields. why isn't this code working?

sullisnyc44
sullisnyc44 used Ask the Experts™
on
I'm attempting to use jquery to hide fields on a new form.

I'm trying to modify the Help Desk template from the fab 40. I thought I was applying code that I have used successfully in the past (with the help of experts in this forum :D)

but it's not working. The field is called ComplianceReview and it is a Yes/No checkbox. I do not want it to show up on new forms.

Attached is my code. And some html about the field.



<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js" type="text/javascript"></script>
<script type="text/javascript">
$(function(){
//hide all of the check-boxes I don’t need
$("a[name$='ComplianceReview']").closest("tr").hide();
});
</script>

Open in new window

<TD nowrap="true" valign="top" width="190px" class="ms-formlabel"><H3 class="ms-standardheader">
		<nobr>Compliance Review</nobr>
	</H3></TD>
		<TD valign="top" class="ms-formbody" width="400px">
		<!-- FieldName="Compliance Review"
			 FieldInternalName="ComplianceReview"
			 FieldType="SPFieldBoolean"
		  -->
			<span dir="none">
		<input id="ctl00_m_g_2a0e593d_0e76_40eb_919b_29c48acea959_ctl00_ctl04_ctl05_ctl00_ctl00_ctl04_ctl00_ctl00_BooleanField" type="checkbox" name="ctl00$m$g_2a0e593d_0e76_40eb_919b_29c48acea959$ctl00$ctl04$ctl05$ctl00$ctl00$ctl04$ctl00$ctl00$BooleanField" /><br>
	</span>
			
			
		</TD>

Open in new window

Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
$("a[name='ComplianceReview']).closest('tr').hide();

You have an extra $ sign in there. Also, IE does not like hiding table rows. You may want to put <tbody></tbody> around that row and change the jquery to closest('tbody')


Author

Commented:
I use this code with no issues on another page (see snippet)

A solution I got from here:
http://www.endusersharepoint.com/2009/07/06/jquery-to-the-rescue-automate-all-day-event/

Where do I have too many "$"?
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js" type="text/javascript"></script>
<script type="text/javascript">
$(function() {
  $('td.ms-dttimeinput').hide(); //hides the times on Start Time
  $('span[title=All Day Event] > input').attr("checked","checked"); // checks All Day Event
  //hide all of the check-boxes I don’t need
  $('tr:has(span[title=Recurrence])').not('tr:has(tr)').hide();
  $('tr:has(span[title=All Day Event])').not('tr:has(tr)').hide();
  $('tr:has(span[title=Workspace])').not('tr:has(tr)').hide();
});
</script>

Open in new window

$("a[name$='ComplianceReview']").closest("tr").hide();
});


you have an extra $ after the word name.
Exploring SharePoint 2016

Explore SharePoint 2016, the web-based, collaborative platform that integrates with Microsoft Office to provide intranets, secure document management, and collaboration so you can develop your online and offline capabilities.

Author

Commented:
hmmmm... does like this either
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js" type="text/javascript"></script>
<script type="text/javascript">
$(function(){
//hide all of the check-boxes I don’t need
     $("a[name='ComplianceReview']").closest("tr").hide();
});
</script>

Open in new window

When you view source of the rendered HTML does the field name match correctly? Same capitalization and everything? Could you post the rendered HTML source?
sorry, must obviously I think you need this...
$("input[name='ComplianceReview']").closest("tr").hide();

You are not applying this to an "a" element, you are binding it to an input.

Author

Commented:
I posted the html for the field in my first post. do you need more than that?

I believe all the capitalization, etc is the way it should be.

this isn't working either (see snippet)
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js" type="text/javascript"></script>
<script type="text/javascript">
$(function(){
//hide all of the check-boxes I don’t need
     $("input[name='Compliance Review']").closest("tr").hide();
});
</script>

Open in new window

Sorry, what I was getting at is that this is the input field in your code...
 <input id="ctl00_m_g_2a0e593d_0e76_40eb_919b_29c48acea959_ctl00_ctl04_ctl05_ctl00_ctl00_ctl04_ctl00_ctl00_BooleanField" type="checkbox" name="ctl00$m$g_2a0e593d_0e76_40eb_919b_29c48acea959$ctl00$ctl04$ctl05$ctl00$ctl00$ctl04$ctl00$ctl00$BooleanField" /><br>

I am assuming that when you call this page from a browser the field does not look like that, rather it gets generated with the actual name="ComplianceReview"

Your example shows the name as Compliance Review, your jQuery calls is ComplianceReview (no space)...those would be two different fields. I was asking to see the source HTML so I could verify what the fieldname actually was.


Author

Commented:
I was attempting both ways. the 'display name' and the internal name.  

That was in the code I posted? So sorry. attached is the complete view source of the newform page.
viewsourceNewForm.htm

Author

Commented:
ahhh I see what you are saying...

how do I fix that?
hmmm. I thought the program was rending the field into the friendly name. I just added this and the row went away...(don't look very pretty)

<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js" type="text/javascript"></script>
<script type="text/javascript">
$(function(){
//hide all of the check-boxes I don't need
     $("input[name='ctl00$m$g_2a0e593d_0e76_40eb_919b_29c48acea959$ctl00$ctl04$ctl05$ctl00$ctl00$ctl04$ctl00$ctl00$BooleanField']").closest("tr").hide();
});
</script>

Author

Commented:
lol. works for me too. :((

ok - how do I fix that?

Why the heck did that happen to the id?

Can I set it to hide all checkboxes?

like something $('tr:has(td[id=SPFieldCalculated])').not('tr:has(tr)').hide();

but boolean?
you could try this for all...

$('input:checkbox').each(function() {
  $(this).closest("tr").hide();
});

Author

Commented:
thanks so much - that was the 'easy' way around it since there are no other checkboxes on the form.

but what happened with my field name?

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial