...

View Full Version : jQuery Jquery slide



extremed
11-23-2010, 11:14 AM
Hi

This is my code to show/hide textarea when checkbox click

how can i add jquery slide to textarea when it show and hide?



1 <input type = "checkbox" id = "chk1" onclick = "toggle(1)">
2 <input type = "checkbox" id = "chk2" onclick = "toggle(2)">
3 <input type = "checkbox" id = "chk3" onclick = "toggle(3)">
4 <input type = "checkbox" id = "chk4" onclick = "toggle(4)">
5 <input type = "checkbox" id = "chk5" onclick = "toggle(5)">

<textarea id = "t1" rows = "4" cols = "50" style="display:none">1</textarea>
<textarea id = "t2" rows = "4" cols = "50" style="display:none">2</textarea>
<textarea id = "t3" rows = "4" cols = "50" style="display:none">3</textarea>
<textarea id = "t4" rows = "4" cols = "50" style="display:none">4</textarea>
<textarea id = "t5" rows = "4" cols = "50" style="display:none">5</textarea>

<script type = "text/javascript">

function toggle(which){
var ta = "t" + which;
var box = "chk" + which
if (document.getElementById(box).checked ) {
document.getElementById(ta).style.display="block";
}
else {
document.getElementById(ta).style.display="none";
}
}
</script>



Sorry for language errors

Thanks

SB65
11-23-2010, 01:05 PM
Here's one way:


$(document).ready(function(){
$('input[type=checkbox]').attr('checked', false).change(function(){//set all the checkboxes to unchecked on load, and add a change event...
var ident = $(this).attr('id').match(/\d+$/);//...to extract the integer from the id...
$('#t'+ ident).slideToggle();//...and display or hide the matching textarea with a slide
});
})

This removes the need for your onClick attributes as well.

extremed
11-23-2010, 01:38 PM
Thanks

also can you help me with jquery copy to clipboard?

this is the text area and i need to copy content into clipboard when click on text area


<textarea id="tx" name='set1' cols='80' rows='10' onClick="ClipBoard();"><?=substr($result['SET1'],0,50)?></textarea>

SB65
11-23-2010, 02:05 PM
There's no native jQuery support for clipboard, although you'll probably find a plugin (http://plugins.jquery.com/project/clipboard) somewhere.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum