简体   繁体   中英

i could't disable submit button on contact form

I've tried all that recommended here to similar posters but nothing has working.

please let me know, what I'm doing wrong? here is the simple code from one of the examples, and works fine when I've tried on jsfiddle, but once i run it on my web page...the button is disable but javascript shows mistake 21(Uncaught ReferenceError: $ is not defined) here is the original link

<form>
    Username<br />
    <input type="text" id="user_input" name="username" /><br />
    Password<br />
    <input type="text" id="pass_input" name="password" /><br />
    Confirm Password<br />
    <input type="text" id="v_pass_input" name="v_password" /><br />
    Email<br />
    <input type="text" id="email" name="email" /><br />
    <input type="submit" id="register" disabled value="Register" />
    </form>
    <div id="test">
    </div>
    <script>$('#user_input, #pass_input, #v_pass_input, #email').bind('keyup', function() {
        if(allFilled()) $('#register').removeAttr('disabled');
    });

    function allFilled() {
        var filled = true;
        $('body input').each(function() {
            if($(this).val() == '') filled = false;
        });
        return filled;
    }</script>

You need to include jquery($) in your code. Easiest way is to include the below line before your script tag where allFilled() logic resides. You can also place it in the <head> tag. But make sure any code which makes use of $ (jquery) remain after the including jquery.

<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>

 $('#user_input, #pass_input, #v_pass_input, #email').bind('keyup', function() { if (allFilled()) $('#register').removeAttr('disabled'); }); function allFilled() { var filled = true; $('body input').each(function() { if ($(this).val() == '') filled = false; }); return filled; }
 <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script> <form> Username<br /> <input type="text" id="user_input" name="username" /><br /> Password <br /> <input type="text" id="pass_input" name="password" /><br /> Confirm Password<br /> <input type="text" id="v_pass_input" name="v_password" /><br /> Email <br /> <input type="text" id="email" name="email" /><br /> <input type="submit" id="register" disabled value="Register" /> </form> <div id="test"> </div>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM