Thursday, September 6, 2012

selecting the text of an li element using Jquery

<script type='text/javascript'>
$("li").click(function(event){
//alert($("this").attr('href'));
console.log($(this).text());
$('#append-here').append($(this).text());
event.stopPropagation();
});
</script>

Saturday, May 19, 2012

This blog involves a simple action using JQuery. It creates a table with checkboxes next to the items. There are buttons for select all checkboxes and unselect all checkboxes. Then the form is submitted to some script on the server. Note the values send to the server are in the format value=on Example




http://action-host.com?_viewClass=md%3AgeneratePDFForm&_base=http%3A%2F%2Flinkedmodel.org%2Fdoc%2F1.0%2Ftemplate&C=on


Also some parameters which are to be sent to the server by default can be sent using hidden input fields.

    <script src="http://code.jquery.com/jquery-latest.js"/>
    <script type="text/javascript">$(document).ready(function(){
    $('#check_all').click(function(){
        $(':checkbox').attr('checked',true);
    });
    $('#uncheck_all').click(function(){
        $(':checkbox').attr('checked',false);
    });
    $('#generate_checked').click(function(){
    $('#pdf_generation_form').submit();
});
});</script>
    <form action="http://localhost:8083/tbl/uispin" id="pdf_generation_form" method="GET">
        <input name="_viewClass" type="hidden" value="md:generatePDFForm"/>
        <input name="_base" type="hidden" value="http://linkedmodel.org/doc/1.0/template"/>
        <table>
               <tr>
                    <td>name1</td>
                    <td>value1</td>
                    <td>
                        <input id="{= ?partLabel }" name="{= ?number }" type="checkbox"/>
                    </td>
                    <td>
                        <button id="generate-pdf">PDF</button>
                    </td>
                </tr>
            </ui:forEach>
        </table>
        <button id="check_all">Check All</button>
        <button id="uncheck_all">Uncheck All</button>
        <input id="generate_checked" type="button" value="Generate Checked"/>
    </form>

To send the values of checkboxes through ajax

 $('#Download_PDF').click(function(){
        var datatosend=$(":checked");
        $.ajax({
    url: "http://someurll?_someparam=somevalue",
    data: datatosend,
    type: "post",
    success: function(data, status, jqXHR){alert(data);},
    error: function(){alert('error');}
});

the name attribute of the checkboxes is sent to th server