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 732803
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T07:11:01+00:00 2026-05-14T07:11:01+00:00

I need to apply/remove to an input field according to a user’s selection in

  • 0

I need to apply/remove to an input field according to a user’s selection in a separate drop down form – but I can’t figure out how to target the input’s class.

I need to add/remove the ‘pageRequired’ class from this input:

<input  type="text" title="Company Required" name="customfields-tf-2-tf" class="inputclass pageRequired textInput" id="customfields-tf-2-tf" />

When the user selects one of two options from a drop down field. For example:

<select class="dropdown" name="customfields-s-1-s" id="customfields-s-1-s" >
<option value="Owner"<?php if(in_array("Owner",$temp_values)) { ?> selected='selected'<?php } ?>> Owner</option>
<option value="Broker"<?php if(in_array("Broker",$temp_values)) { ?> selected='selected'<?php } ?>> Broker</option>
</select>

If the user selects broker than I want to add the pageRequired class to the first input field and remove it if the user selects Owner.

EDIT- Ok, so here is the code I am working with:

<script type="text/javascript">
function changeClass(myDropdown) {
   if (#customfields-s-1-s.selectedIndex == 1 ) {
       $('#customfields-tf-2-tf').addClass('pageRequired');
   }
   else {
      $('#customfields-tf-2-tf').removeClass('pageRequired');
   }
}
</script>
  • 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-14T07:11:02+00:00Added an answer on May 14, 2026 at 7:11 am

    This can be done very simply using jquery:

    Just add the onchange event to your dropdown and then call a function that either removes the class or adds it depending on the dropdown selection

    <select class="dropdown" name="customfields-s-1-s" id="customfields-s-1-s" onchange="javascript:changeClass(this);" >
    
    function changeClass(myDropdown) {
       if (myDropdown.selectedIndex == 1 ) {
           $('#customfields-tf-2-tf').addClass('pageRequired');
       }
       else {
          $('#customfields-tf-2-tf').removeClass('pageRequired');
       }
    }
    

    Here are the links on use:

    http://api.jquery.com/addClass/

    http://api.jquery.com/removeClass/

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i have a input tag which is non editable, but some times i need
I need to apply some xml templates to various streams of xml data (and
I need to apply a style in code ike this: TextBlock.Style = TryFindResource(MyStyle) as
My current program need to use programatically create a XPathExpression instance to apply to
This is probably quite a newb question, but I can't seem to figure it
I'm trying to apply the css on the a href, basically i need to
I need to solve the following question which i can't get to work by
I have an HTML ordered list, that I need to apply a strikethrough to.
I apply a filter to Dataview and after that I need to get the
Do I need to register new extension types with Apple before I release an

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.