I have this form that has a textarea that is compulsory, it has a checkbox that allows it to be ticked to show a hidden textarea using css/jquery.
What I would like is to know how to do the jquery to force input into the unhidden textarea only when the checkbox is ticked
heres the css onload to hide it
div.textarea {
display: none;
}
heres my current jquery, top one displays the textarea if the checkobx is ticked, bottom one is the validation rules.
Needs to have some sort of if checkbox checked moreData required true, but i ahve no idea how to do this.
$(document).ready(function() {
var visible = false;
$('input[name="moreData"]').click(function() {
var divs = $('div.textarea');
if (visible) {
divs.each(function() {
this.style.display = 'none';
});
visible = false;
}
else {
divs.each(function() {
this.style.display = 'block';
});
visible = true;
}
});
});
$(document).ready(function() {
// validate the comment form when it is submitted
$("#test").validate({
rules:
{
usernames:
{
required: true
},
moreData:
{
required: false
},
},
messages:
{
usernames: "<font color=\"red\" >User name required</font>"
}
});
});
here is the html
<input type="checkbox" id="moreData" name="moreData" >More job description data required</b><br>
<div class="textarea">
<textarea rows="40" Cols="90"></textarea>
</div>
</form>
Any help much appreciated.