GoFuckYourself.com - Adult Webmaster Forum

GoFuckYourself.com - Adult Webmaster Forum (https://gfy.com/index.php)
-   Fucking Around & Business Discussion (https://gfy.com/forumdisplay.php?f=26)
-   -   how to clear an input after submit in jquery? (https://gfy.com/showthread.php?t=1012835)

fris 03-04-2011 09:00 AM

how to clear an input after submit in jquery?
 
here is the code i have (it does live search)

Code:

jQuery(document).ready(function ($) {
    var contentCache, searched = false;
    jQuery('#searchform').submit(function () {
        var s = jQuery(this).find('#s').val();
        if (s.length == 0) {
            return;
        }
        var submit = $('#searchsubmit');
        submit.attr('disabled', false);
        var url = jQuery(this).attr('action') + '?s=' + encodeURIComponent(s) + '&action=search_ajax'
        jQuery.ajax({
            url: url,
            type: 'get',
            dataType: 'html',
            beforeSend: function () {

                submit.attr('disabled', true).fadeTo('slow', 0.5);
                document.body.style.cursor = 'wait';
                var load = '<div id="content" role="main"><h1 class="page-title">Searching...</h1></div>';
                jQuery('#container').empty().html(load);
            },
            success: function (data) {
                submit.attr('disabled', false).fadeTo('slow', 1);
                document.body.style.cursor = 'auto';
                jQuery('#container').empty().html(data);
                jQuery('#ajaxback').click(function () {
                    jQuery('#container').empty().html(contentCache);
                });

            }

        });
        return false;
    });
    var timer, currentKey;
    jQuery('#s').keyup(function () {
        clearTimeout(timer);
        timer = setTimeout(function () {
            var sInput = jQuery('#s');
            var s = sInput.val();
            if (s.length == 0) {
                if (searched) {
                    jQuery('#container').empty().html(contentCache);
                    sInput.focus();
                    //jQuery('#search-form span.processing').remove();
                    searched = false;
                }
                currentKey = s;
            } else {
                if (s != currentKey) {
                    if (!searched) {
                        contentCache = jQuery('#container')[0].innerHTML;
                        searched = true;
                    }
                    currentKey = s;
                    if (s != ' ') {
                        jQuery('#searchform').submit();
                    }
                }
            }
        }, 800);
    });

});


borked 03-04-2011 12:34 PM

huh? Why do you want to clear the form? Why not have it clear the next time the cursor is clicked on the text field? That way the user still sees their search term in the text form?

Anyway, a simple form reset should suffice no?

onsubmit="this.submit(); this.reset();"


All times are GMT -7. The time now is 08:49 AM.

Powered by vBulletin® Version 3.8.8
Copyright ©2000 - 2025, vBulletin Solutions, Inc.
©2000-, AI Media Network Inc123