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

  • SEARCH
  • Home
  • 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 879211
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T11:53:41+00:00 2026-05-15T11:53:41+00:00

Im trying to set up a form where a user has to pick an

  • 0

Im trying to set up a form where a user has to pick an option from a select or enter a value in an input. One must be required but not both. I was attempting to write an if else statement

if the state is selected then remove the class on province, if province is filled then remove class on state

$("#state").bind('change' , function() {
     if ( $(this).is(':selected') ) {
          $(this).parents('.foreign').removeClass("required");
      }  
      else{
      $(#province).is(':filled');
      $(this).parents('.usa').removeClass("required");
          }  
});

But I know this is not how to do it. Hopefully someone gets the idea of what I am trying. thanks in advance! Basically you can pick this or that but not both.

  • 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-05-15T11:53:42+00:00Added an answer on May 15, 2026 at 11:53 am

    Off the top of my head, try this:

    <select id="state_province">
       <option value="state">State</option>
       <option value="province">Province</option>
    

    $('#state_province').bind('change', function() {
       if($('option:selected', this).val() == 'state') {
          $('option[value=state]', this).show().addClass("required");
          $('option[value=province]', this).hide().removeClass("required");
       } else {
          $('option[value=province]', this).show().addClass("required");
          $('option[value=state]', this).hide().removeClass("required");
       }
    });
    

    Edit based on your comment:

    Ah, so you want something like: (sorry, I’m doing this from memory, so there may be tweaks)

    <select id="state" class="state_province">
    ...
    </select>
    
    <input type="text" id="province" class="state_province" />
    

    ===

    $('.state_province').bind('change', function() {
       var jThis = $(this);
       if ( jThis.is('select:selected') ) { // state selected
          jThis.addClass("required");
          $('input.state_province').removeClass("required");
          $(this).parents('.usa').addClass("required");
       }
       if ( jThis.is('input:filled') ) { // province filled
          jThis.addClass("required");
          $('select.state_province').removeClass("required");
          $(this).parents('.usa').removeClass("required");
       }
    });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've been trying to set the value of a hidden field in a form
I am trying to set up a nested model form similar to the one
Im trying set the single table inheritance model type in a form. So i
I am trying to set the click event of a button on my form
Trying to set it so if a certain condition is met then one of
I'm trying to create a user control which has a DataSource, which can accept
I’m trying to create a script for a user to enter in their username,
I am trying to set up a preview button in an edit form based
My FlipViewController has some setting in form of UISwitches for MainViewController. I am trying
I am trying to start a PHP session to store data from a form

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.