Hi! I have one form with input type=text but I want to put there only amounts that are bigger or equal $minimalamount if the amount will be smaller i want to show warning, and do not process form. How can I do it ?
if $minimalamount comes from your database or is created with some php, it might be better to do your test with php and create your html code from there with something like: <?php if($minimalamount>=1000){ $val = $minimalamount; }else{ $val = "WARNING"; } ?> <input type="text" name="myfieldname" id="myfieldid" value="<? echo $val; ?>"> PHP: You should use Javascript only if you have an interaction between the user and the form. you can call your action with the "onBlur" trigger, or use the jquery function .blur() on your field, which will give you something like: <script type="text/javascript"> $(document).ready(function () { $('#myfieldid').blur(function(){ if($(this).val()<1000){ //do your action here: $(this).val('WARNING'); } }); }); </script> Code (markup):
It didn't work'ed My input look just like this: And I did like you sayed: <script type="text/javascript"> $(document).ready(function () { $('amount').blur(function(){ if($(this).val()<10){ //do your action here: $(this).val('WARNING'); } }); }); </script>
well <? $kwota ?> is php, so you should definitely use php and not javascript. The blur() function needs the user to edit the field to be triggered. If you really want to use jquery, don't forget to call the library. In php, if you replace <? $kwota ?> PHP: by <? if($kwota >=10){ echo $kwota ; }else{ echo "WARNING";} ?> PHP: it should work
Nope, It redirected me into site where user shoud put number higher or equal 10 ... I want it just to return into site with form, or show error and do not redirect anywhere.