Ok, so here's what I want to do, preferably with jQuery 1.4.2:
- Have one <input type="text"开发者_如何学Go>and one<input type="button">
- If the text-inputhas exactly N number characters, I want a click on thebuttonto submit the form with one action.
- Else, the button submits the form with another action.
Unfortunately I'm a jQuery n00b, and I can't get it to work… ._.
If you use a <button type="submit">, you could handle the form's submit event and change the action accordingly, so that the submit directs to the page you want.  This should be the easiest way, with minimal code necessary -- something like:
var myForm = $('#myForm');
myForm.submit(function ()
{
    if ($('#myInput').val().length == 42)
        myForm.attr('action', 'http://somewhere.com');
    else
        myForm.attr('action', 'http://somewhereelse.com');
}
To get the number of characters, do $('input[type=text]').val().length
This questions chosen answer should help. Place that code (once you have adapted) below:
$("myFormID").submit( function () {
//Put adapted code here
} )
;
$(function() {
        $('#button').click(function() {
            var textLength = $('#text').val();
            if (textLength.length === 10) // 10 for exmaple
            {
                //do bla
            }
            else { 
                // do labla
            }
        });
    });
 
         
                                         
                                         
                                         
                                        ![Interactive visualization of a graph in python [closed]](https://www.devze.com/res/2023/04-10/09/92d32fe8c0d22fb96bd6f6e8b7d1f457.gif) 
                                         
                                         
                                         
                                         加载中,请稍侯......
 加载中,请稍侯......
      
精彩评论