Note that there are some explanatory texts on larger screens.

plurals
  1. POValidation in JavaScript : empty textbox when click the button
    primarykey
    data
    text
    <p>I need to validate my textbox using JavaScript, so far i made this :</p> <pre><code>$(document).ready(function(){ $('#search_form').validate({ rules: { searchText:{ required: true, number: true }, }, messages: { searchText: { required: "required", number: "must be a number" }} })} ); </code></pre> <p>it works fine but i also need to show a message if user presses the search button without enter any value, and of course the textbox is containing the message "please enter your number" (using placeholder).</p> <p>the serach form :</p> <pre><code>&lt;form method="get" id="search_form"&gt; &lt;input type="button" value="search" id="search" /&gt; &lt;input type="text" name="searchText" id="searchText" placeholder="please enter your number" /&gt; &lt;/form&gt; </code></pre> <p>the current code doesn't show anything <strong>if user presses search button</strong> without inserting a number, but if he inserts letters for example he will get the message "must be number" and if he deletes any value was there in textbox, he will get the message "required".</p> <p>i tried : </p> <pre><code>searchText:{ required: { depends: function() { return $( "#searchText" ).val() == 'please enter your number '} }, number: true }, </code></pre> <p>but nothing changes.</p> <p>i hope i could explain my question good.</p> <hr> <p>Thanks!</p> <p>you are right it works fine if i delete whatever value in the textbox i get required msg. but since i made the validation on the form, it didn't response on the button clocking. how i can add a validation on the button too ? </p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload