Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

jQuery question

Status
Not open for further replies.

FALCONSEYE

Programmer
Jul 30, 2004
1,158
US
Is there a way to get a checkbox value from its className? I am trying to implement a toggle() function. When a user clicks on a checkbox it shows a textarea to enter stuff. They can use upto 10 textareas. On page load, I show only 4 textareas. Right underneath, there is a checkbox to add/remove the textarea. On show(), I will need to add another checkbox in case they want to use the 5th text area. This is what I have so far:


Code:
<script>
$(document).ready(function() {
	<cfoutput>
	<cfloop index="j" from="4" to="10">
	$('[class^=toggle-item-link#j#]').hide();
	$('[class^=container#j#]').hide();
	</cfloop>
	</cfoutput>	
	$('[class^=link]').click(function() {
		var $this = $(this);
		var x = $this.attr("className");
		
		var y = $(x).val();
		alert('this is y:'+y);
		alert(x);
		$('.toggle-item-' + x).toggle();
		$('[class^=container4]').show();
		return false;
	});
});
</script>

this is the checkbox:
Code:
<input type="checkbox" name="addNew#i#" id="addNew#i#" class="link#i#" value="#i#">

 
oops. I found a solution:

Code:
	$('[class^=link]').click(function(event) {
		var $this = $(this);
		var x = $this.attr("className");
		//ar y = toString($this.attr("className")).text().charAt(4);
		var y = this.id.replace('addNew', "");
		alert('this is y:'+y);
		alert(x);
		$('.toggle-item-' + x).toggle();
		$('[class^=container4]').show();
		return false;
	});

I pass the event to the function, then to a replace to get the number. thanks

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top