[jQuery] Jquery validation pluggins how to delete rows and to hide some parts of the form (newbie question)

[jQuery] Jquery validation pluggins how to delete rows and to hide some parts of the form (newbie question)


I have adapted the Jquery validation plugion example to start an
accounting interface with debit/credit and multiple currencies.
However, I would like to hide the credit column if the first tickbox
is not ticked, and would like to hide the debit column if the first
tickbox is ticked. I would like to show an empty space rather than an
input Box.
1. For example, if box is not ticked:
[ ] [account] [debit] [usd]
[debit] [delete line]
2. For example, if box is ticked:
[X] [account] [credit] [usd]
[credit] [delete line]
Pressing the tick box will toggle between 1. and 2.
In addition, I would like to be able to delete a line by pressing the
[delete line] button.
How can I do that, I don't know how to hide the cell debit/credit?
please see code below:
<?xml version="1.0" encoding="ISO-8859-1" ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://
www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html;
charset=ISO-8859-1" />
<title>jQuery validation plug-in - dynamic forms demo</title>
<link rel="stylesheet" type="text/css" media="screen" href="css/
screen.css" />
<script src="../lib/jquery.js" type="text/javascript"></script>
<script src="../jquery.validate.js" type="text/javascript"></script>
<script type="text/javascript">
// only for demo purposes
$.validator.setDefaults({
    submitHandler: function() {
        alert("submitted!");
    }
});
$.validator.messages.max = jQuery.format("Your totals musn't exceed
{0}!");
$.validator.addMethod("quantity", function(value, element) {
    return !this.optional(element) && !this.optional($(element).parent
().prev().children("select")[0]);
}, "Please select both the item and its amount.");
$().ready(function() {
    $("#orderform").validate({
        errorPlacement: function(error, element) {
            error.appendTo( element.parent().next() );
        },
        highlight: function(element, errorClass) {
            $(element).addClass(errorClass).parent().prev().children
("select").addClass(errorClass);
        }
    });
    var template = jQuery.format($("#template").val());
    function addRow() {
        $(template(i++)).appendTo("#orderitems tbody");
    }
    var i = 1;
    // start with one row
    addRow();
    // add more rows on click
    $("#add").click(addRow);
    // check keyup on quantity inputs to update totals field
    $("#orderform").delegate("keyup", "input.debit_functional", function
(event) {
        var totals = 0;
        $("#orderitems input.debit_functional").each(function() {
            totals += +this.value;
        });
        $("#totaldebit").attr("value", totals).valid();
    });
    // check keyup on quantity inputs to update totals field
    $("#orderform").delegate("keyup", "input.credit_functional", function
(event) {
        var credittotal = 0;
        $("#orderitems input.credit_functional").each(function() {
            credittotal += +this.value;
        });
        $("#totalcredit").attr("value", credittotal).valid();
    });
});
</script>
<script type="text/javascript">
$(document).ready(function(){
//Hide div w/id extra
$("#extra").css("display","none");
// Add onclick handler to checkbox w/id checkme
$("#checkme").click(function(){
// If checked
if ($("#checkme").is(":checked"))
{
//show the hidden div
$("#debit").show("fast");
$("#credit").hide("fast");
}
else
{
//otherwise, hide it
$("#debit").hide("fast");
$("#credit").show("fast");
}
});
});
</script>
<style type="text/css">
form.cmxform { width: 50em; }
em.error {
background:url("images/unchecked.gif") no-repeat 0px 0px;
padding-left: 16px;
}
em.success {
background:url("images/checked.gif") no-repeat 0px 0px;
padding-left: 16px;
}
form.cmxform label.error {
    margin-left: auto;
    width: 250px;
}
form.cmxform input.submit {
    margin-left: 0;
}
em.error { color: black; }
#warning { display: none; }
select.error {
    border: 1px dotted red;
}
</style>
</head>
<body>
<h1 id="banner"><a href="http://bassistance.de/jquery-plugins/jquery-
plugin-validation/">jQuery Validation Plugin</a> Demo</h1>
<div id="main">
<textarea style="display:none" id="template">
    <tr>
        <td>
        </td>
        <td class='type'>
<input id="checkme-{0}" type="checkbox"
name="debitcredit" value="D">
</td>
        <td class='account_from_chart'>
            <select>
                <option value="1">Income</option>
                <option value="2">Expense</option>
            </select>
        </td>
        <div id="debit">
<td class='debit'>
            <input size='4' class="quantity" min="1" id="item-quantity-{0}"
name="item-quantity-{0}" />
        </td>
</div>
<div id="credit" >
        <td class='credit'>
            <input size='4' class="quantity" min="1" id="item-quantity-{0}"
name="item-quantity-{0}" />
        </td>
<div>
        <td class='currency'>
            <select name="item-type-{0}">
                <option value="USD">USD</option>
                <option value="GBP">GBP</option>
            </select>
        </td>
        </td>
        <td class='debit_functional'>
            <input size='4' class="debit_functional" min="0.01" id="item-
quantity-{0}" name="item-quantity-{0}" />
        </td>
        <td class='credit_functional'>
            <input size='4' class="credit_functional" min="0.01" id="item-
quantity-{0}" name="item-quantity-{0}" />
        </td>
<td> <button id="delete_line">Delete</button> </td>
        <td class='quantity-error'></td>
    </tr>
</textarea>
<form id="orderform" class="cmxform" method="get" action="foo.html">
    <h2 id="summary"></h2>
    <fieldset>
        <legend>Example with custom methods and heavily customized error
display</legend>
        <table id="orderitems">
            <tbody>
            </tbody>
            <tfoot>
                <tr></tr>
                <tr>
                    <td colspan="9"></td>
                    <td class="totaldebit"><input id="totaldebit" name="totaldebit"
value="0" readonly="readonly" size='4' /></td>
<td class="totalcredit"><input
id="totalcredit" name="totalcredit" value="0" readonly="readonly"
size='4' /></td>
                </tr>
                <tr>
                    <td colspan="2">&nbsp;</td>
                    <td><input class="submit" type="submit" value="Submit"/></td>
                </tr>
            </tfoot>
        </table>
    </fieldset>
</form>
<button id="add">Add another input to the form</button>
<h1 id="warning">Your form contains tons of errors! Please try again.</
h1>

<a href="index.html">Back to main page</a>


</div>
<script src="http://www.google-analytics.com/urchin.js" type="text/
javascript">
</script>
<script type="text/javascript">
_uacct = "UA-2623402-1";
urchinTracker();
</script>
</body>
</html>
</head>
<body>
    <div style="width: 500px;">
        <form>
            <label for="name">Name:</label>
            <input id="name" type="text">
            <label for="checkbox">Check to enter your email address:</label>
            <input id="checkme" type="checkbox" />
            <div id="extra">
                <label for="email">debit:</label>
                <input id="email" type="text" />
            </div>
            <div id="extra2">
                <label for="email">credit:</label>
                <input id="email" type="text" />
            </div>
        </form>
</body>
</html>