Note that there are some explanatory texts on larger screens.

plurals
  1. POUnique textbox required issue with jQuery
    primarykey
    data
    text
    <p>I have a small form with three fields that are all required.</p> <pre><code>&lt;div class="span5 offset3 well"&gt; &lt;legend&gt;To begin, please enter the info below&lt;/legend&gt; &lt;div class="alert alert-error hide" id="error"&gt; &lt;span&gt;Incorrect Username or Password!&lt;/span&gt; &lt;/div&gt; &lt;form accept-charset="UTF-8" action="" method="POST" name="check_form" id="check_form"&gt; &lt;p&gt; &lt;label&gt;Student ID&lt;/label&gt; &lt;input type="text" id="txtEmplid" placeholder="Student ID" name="txtEmplid" class="span5"&gt; &lt;/p&gt; &lt;p&gt; &lt;label&gt;Email address&lt;/label&gt; &lt;input type="text" placeholder="Email address" id="txtEmail" name="txtEmail" class="span5"&gt; &lt;/p&gt; &lt;p&gt; &lt;label&gt;OR&lt;/label&gt; &lt;/p&gt; &lt;p&gt; &lt;label&gt;DOB&lt;/label&gt; &lt;input type="text" placeholder="Date of Birth" id="dob" name="dob" class="span5"&gt; &lt;/p&gt; &lt;button type="submit" id="doCheck" name="doCheck" class="btn btn-warning"&gt;Submit&lt;/button&gt; &lt;input type="hidden" value="form-submit" name="form-submit"&gt; &lt;/form&gt; &lt;/div&gt; </code></pre> <p>Originally, this was fine. However, now I need to modify it so that the user is required to enter the ID and at least one of the other two. For example. Id and DOB are filled out, but Email is blank. </p> <p>Initially, I wrote a small jQuery function that I used to change the background color of any text box that was empty to red. Here is that code:</p> <pre><code>function doFieldEmpty(input) { var ic = 0; var $i = input; $i.each(function( index, value ) { // if empty, add red background class if ($(this).val() == '') { $(this).addClass('inputerror') .attr('placeholder', 'Required') .val(index); } else { $(this).removeClass('inputerror'); } }); } </code></pre> <p>I call it using this.</p> <pre><code>doFieldEmpty($("#studentid, #email, #dob")); </code></pre> <p>Since this code already loops through the jQuery object, I'm a bit hesitant to write another function that does what I want. </p> <p>So my question is, how can I modify this function that it does both. </p> <p>I hope I've explained in enough detail for what I'm looking for. Thanks in advance.</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.
 

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