Clear popup form
  • I have a popup form and i want to clear the form when a user clicks on Add button from the popup.
    I have these functions:
    function initDialog() {
        var myId =;
        var $dlog = $(this),
            opts = { buttons: { "OK": hideDialog, "Add": addComponentInDialog} };


        $dlog.before("<a class='satellite-content' href='#{id}' onclick=\"showDialog('{id}'); return false;\">Details</a>".replace(/\{id\}/g, myId));

    function addComponentInDialog() {
        return addComponent2( $(this) );
    function addComponent2($container) {
        // TODO: Put an error check in here to make sure $container has children

        var $ctx = $container.find("[class]:first-child").eq(0).clone(), // Performance implications w/ this selector? Perhaps ":first-child[class]"?
            re = /([^_]+)\[(\d+)\]/g, // Finds all "array" names in the ID string, with their indexes
            segment = $ctx.attr("id").match(re);
        if (!$.isArray(segment) || segment.length < 1) return// Error check; matching failed
        segment = segment.pop(); // Get the last array name & index
        var i = $container.children("[class]").size(), // 1 + parseInt(segment.match(/\d+/)[0]), // guaranteed b/c of earlier regexp
            repl = segment.replace(/\d+/, i);

        segment = new RegExp("(\\$|_)" + escapeBrackets(segment), "g");
        repl = "$1" + repl;

        $ctx.attr("id", $ctx.attr("id").replace(segment, repl));
        $ctx.html($ctx.html().replace(segment, repl));
        var name = $ctx.attr("name");
        if (!!name)
            $ctx.attr("name", name.replace(segment, repl));


        $($container).prepend("<br />").prepend($ctx);

        return $ctx;
    function cleanFormFields($context) {

        if (!!$context)
    But when i click on Add from the popup nothing happen.How do i fix this issue?
    I think clearFormFields function is not working

    390 x 389 - 12K
  • 1 Comment sorted by
  • give one name class to all text boxes which you want to clear like (class='orderLine').
    now bind the click method on add button like this it works :)
    $(function() {
    $('.addbutton').click(function() {
    $('.orderLine input[type="text"]').val('');
    just put this line in cleanFormFields function 
    $('.orderLine input[type="text"]').val('');

Howdy, Stranger!

It looks like you're new here. If you want to get involved, or you want to Ask a new Question, Please Login or Create a new Account by Clicking below

Login with Facebook


Popular Posts of the Week