Minimum value in textfield

<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript">

$.fn.updater = function ()
{
	$("div#db_res").load('result.php', { qs: $(this).val() });
	return this;
};

$(document).ready(function(){

	$("input[name='qs']").updater().focus().keyup(function(){
		var str = $(this).val(); 
		$("div#result").html( "Input: " + str ); 
		$(this).updater(str);
	});

});
</script>
	
	<form action="index.php" method="get">
	<input type="text" name="qs" value=""><input type="submit">
	</form>

	<div id="result">Input: <?php echo $_GET['qs']; ?></div>
	<div id="db_res"></div>

Hi,

is it possible somehow first 3 characters is typed into textfield before it can submits?

You can download the validation plugin from http://bassistance.de/jquery-plugins/jquery-plugin-validation/

The demo page shows you how it’s commonly used.

$.fn.updater = function ()
{
     $("div#db_res").load('result.php', { qs: $(this).val() });
     return this;
};

$(document).ready(function(){

    $("input[name='field']").updater().focus().keyup(function(){
    var str = $(this).val();
    $("div#result").html( "Input: " + str );
    $(this).updater(str);
});
});

I have tested that “minlength-validate-code” separate and it work. Allso downloaded all file I need for it but problem is how to use it with above code. Any ideas how to use it together?

<script type="text/javascript">

$(document).ready(function(){
// validation code here

$("#myform").validate({
  rules: {
    field: {
      required: true,
      minlength: 3
    }
  }
});

// updater  code here

$.fn.updater = function ()
{
	$("div#db_res").load('result.php', { field: $(this).val() });
	return this;
};

	$("input[name='field']").updater().focus().keyup(function(){
		var str = $(this).val();
		$("div#result").html( "Input: " + str );
		$(this).updater(str);
	});

});
</script>
<form id="myform" action="index.php" method="get">
    <input id="field" name="field">
    <input type="submit" value="Validate!">
    </form>



Hmm, dont know if i followed your instruction correct or not, but still not work really. Submit button work after I typed in 3 characters but result.php loads as soon something typed in.

$.fn.updater = function ()
{
     $("div#db_res").load('result.php', { qs: $(this).val() });
     return this;
};

$(document).ready(function(){

    $("input[name='field']").updater().focus().keyup(function(){
    var str = $(this).val();
    $("div#result").html( "Input: " + str );
    $(this).updater(str);
});
});
</script>
	
    <form id="myform" action="index.php" method="get">
    <input id="field" name="field">
    <input type="submit" value="Validate!">
    </form>

I have change form and field name efter this code from jquery, but dont know how to use it really with rest of code above. Anyone know how to use? I cant get it work.

$("#myform").validate({
  rules: {
    field: {
      required: true,
      minlength: 3
    }
  }
});

I tested this from some other form someone helped me with before. It work and load a page after 3 characters for form and textfield it is used for.

<input type=‘text’ name=‘q’ value=‘$q’ onkeyup=‘if(this.value.length>=3){searchresult(this.value);}’>

I tested similar on this form but didn’t work. Jquery (even normal JavaScript) is new and to advanced.

Consider the keyup function. Should it do its thing if the form field is not valid? If not, put in a sanity-check at the start of the keyup function so that if the keyup function should not run, you can return out of the function.

Not sure if that help in this case? I can’t see why minlength only work when try to click in submit-button. Update codesnip seems run whit or whiteout minlength anyway. Should work even for update because it is same text field?

I tested that code-snip, just pasted in somewhere $(document).ready(function() section but didn’t help. I guess i need some rest I think, worked on this more than 15-20 hours. Thanks for your help pmw57 anyway. Im m sure it will help in this case but i will look more on that valid method link later.

As you’re using jQuery, you might want to make use of the validation plugin, which has a [url=“http://docs.jquery.com/Plugins/Validation/Methods/minlength#length”]minlength option that you can set.

You can place it as a separate section in the document ready part of the code.


$(document).ready(function(){
    // validation code here

    // updater  code here
});

Which indicates that you need to check if the form is valid before resut.php is loaded. The validators valid method would be appropriate to use for that task.