Link to home
Start Free TrialLog in
Avatar of sullisnyc44
sullisnyc44Flag for United States of America

asked on

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

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

Avatar of mackaboogie
mackaboogie

$("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')


Avatar of sullisnyc44

ASKER

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


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

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?
ASKER CERTIFIED SOLUTION
Avatar of mackaboogie
mackaboogie

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
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?