Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7711647
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T01:25:43+00:00 2026-06-01T01:25:43+00:00

I am working disabling the middle name field if the first name field is

  • 0

I am working disabling the middle name field if the first name field is not filled out first. I have the following code, which disables this in my jQuery Mobile application, but the input is still able to add text to even if the first name is blank and the middle name field stays greyed out if the first name field is filled out. Any help is greatly appreciated. Thanks!

HTML:

<form id="search-form" name="search-form" method="post">
      <div class="formBox">
        <div data-role="fieldcontain">
          <label for="firstName">First Name</label><br/>
          <input type="text" name="firstname" id="firstNameCriteria" value="" />
        </div>
        <div data-role="fieldcontain">
          <label for="middleName">Middle Name</label><br/>
          <input type="text" name="middleName" id="middleNameCriteria" value="" />
        </div>
        <div data-role="fieldcontain">
          <label for="lastName">Last Name <span class="required">(Required - Must be exact match)</span></label><br/>
          <input type="text" name="lastname" id="lastNameCriteria" value="" />
        </div> 
        </div>

      </div>
     </form>

JS:

$('#firstNameCriteria').each(function() {
      if ($(this).val() == '') {
          $('#middleNameCriteria').addClass('ui-disabled');
          $('#middleNameCriteria').disable('input');
      } else {
          $('#middleNameCriteria').removeClass('ui-disabled');
      }
  });
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-01T01:25:44+00:00Added an answer on June 1, 2026 at 1:25 am

    jQuery Mobile has it’s own helper methods for disabling/enabling form elements that have been initialized by the jQuery Mobile framework: http://jquerymobile.com/demos/1.1.0-rc.1/docs/forms/textinputs/methods.html

    //bind event handler to first text input
    $('#firstNameCriteria').bind('keyup', function () {
    
        //enable or disable the next element based on the value of this one
        var state = (this.value == '') ? 'disable' : 'enable';
        $("#middleNameCriteria").textinput(state);
    });
    

    Here is a demo: http://jsfiddle.net/ycUnv/

    You can use whatever event you like; change will fire once the text input has been blurred and it’s value has changed, keyup will fire just after the user presses a key and the value of the input is updated.

    Also, your HTML has an extra closing </div> tag, this is how it should look:

    <form id="search-form" name="search-form" method="post">
        <div class="formBox">
            <div data-role="fieldcontain">
                <label for="firstName">First Name</label><br/>
                <input type="text" name="firstname" id="firstNameCriteria" value="" />
            </div>
            <div data-role="fieldcontain">
                <label for="middleName">Middle Name</label><br/>
                <input type="text" name="middleName" id="middleNameCriteria" value="" />
            </div>
            <div data-role="fieldcontain">
                <label for="lastName">Last Name <span class="required">(Required - Must be exact match)</span></label><br/>
                <input type="text" name="lastname" id="lastNameCriteria" value="" />
            </div> 
        </div>
    </form>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I tried disabling text selection using JQuery. It's working fine in Firefox but not
The onclick function is not working properly as it is disabling all the links
In this code i am disabling the submit button when i clicked once and
What Is Working Fine I have 2 activities in my app. First activity calls
I'm working on a Web project using Asp.Net MVC, which I'll have to deploy
Working on my first Rails project, I used Ryan Bates' Nifty-Generators to create the
My site was working fine until I followed this guide, http://www.howtoforge.com/how-to-set-up-apache2-with-mod_fcgid-and-php5-on-ubuntu-9.10 to set up
I have three JSF apps working on glassfish 3.1 opensource edition. One of them
I'm working on a web form which works fine as long as it posts
I am currently working on an application that launches separate processes which display additional

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.