开发者

jQuery run function only if input fields are empty

I have a survey of which I开发者_运维百科 want to record a user starting to complete it, by capturing the very first change in any input field or textarea.

So, if all fields (except hidden fields) are blank and any input / textarea change() is detected, I want to run the function rec_start.

if( allBlank ) { rec_start(); }

How can I detect allBlank? I asked this question here but added the hidden fields exception too late ... I'll accept answers in both question once I have a working solution.

Thanks


You want to check for a change in a field e.g.

<script>
    $('input').change(function(){
        if( ($(this).val()=='' || $(this).val()=='the_default_value') && $(this).attr('type')!='hidden') { // might want to do the default value using $.data and looping through $(input) and storing their $(this).attr('value') in $.data
            //the field is empty react as you may
        }
    });
</script>
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜