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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T03:16:19+00:00 2026-05-24T03:16:19+00:00

I have this jQuery script: // sorting the names of the fields we’re hiding

  • 0

I have this jQuery script:

// sorting the names of the fields we're hiding
var timeFieldArray = ["reserveTimeOfDay","choice1TimeOfDay","choice2TimeOfDay","choice3TimeOfDay"];
// show/hide an optional field for the time of day 
$.each(timeFieldArray, function(index, fieldName) 
{   // Start by hiding everything
    $("#"+ fieldName + "Optional").hide();
    $(".toValidate select[name='"+fieldName+"']").click(function() { 
        // is it selected & the correct value? 
        if($("option[value='OtherField']").is(":selected")){
            $("#"+ fieldName + "Optional").show("fast");
            $("input[name='"+fieldName+"Optional']").addClass("required"); 
        } else {
            $("input[name='"+fieldName+"Optional']").removeClass("required");
            $("#"+ fieldName + "Optional").hide();
        }
    }); // closing .Click
}); // closing .Each

Basically, when the Other option is selected I want to take the correct position from timeFieldArray and show the box that relates to that field. The problem is when I select another option field that is not the OtherFieldvalue these still show up. Any suggestions?

My HTML:

<ul>
    <li>
        <p><strong>First Choice</strong></p>
        <p><label for="choice1Date">Date</label><input type="" name="choice1Date" class="dateField required" /></p>
        <label for="choice1TimeOfDay">Time Of Day</label>
        <select name="choice1TimeOfDay">
            <option value="am"> Morning (A.M.)</option>
            <option value="pm"> Afternoon (P.M.)</option>
            <option value="OtherField"> Other </option>                     
        </select>
        <div id="choice1TimeOfDayOptional">
            Other: <input type="text" name="choice1TimeOfDayOptional" /> 
        </div>
    </li>
    <li>
    <p><strong>Second Choice</strong></p>
        <p><label for="choice2Date">Date</label><input type="" name="choice2Date" class="dateField required" /></p>
        <label for="choice2TimeOfDay">Time OF Day</label>
        <select name="choice2TimeOfDay">
            <option value="am"> Morning (A.M.)</option>
            <option value="pm"> Afternoon (P.M.)</option>
            <option value="OtherField"> Other </option>                     
        </select>
        <div id="choice2TimeOfDayOptional">
           Other: <input type="text" name="choice2TimeOfDayOptional" /> 
        </div>
    </li>
    <li>
        <p><strong>Third Choice</strong></p>
        <p><label for="choice3Date">Date</label><input type="" name="choice3Date" class="dateField required" /></p>
        <label for="choice3TimeOfDay">Time Of Day</label>
        <select name="choice3TimeOfDay">
            <option value="am"> Morning (A.M.)</option>
            <option value="pm"> Afternoon (P.M.)</option>
            <option value="OtherField"> Other </option>                     
        </select>
        <div id="choice3TimeOfDayOptional">
           Other: <input type="text" name="choice3TimeOfDayOptional" /> 
        </div>                                    
    </li>
</ul>
  • 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-24T03:16:20+00:00Added an answer on May 24, 2026 at 3:16 am

    You are checking for some option with the Other value that’s selected. Instead, you should check for the current select box whether it has the Other value selected.

    So:

    if($(this).find("option[value='OtherField']").is(":selected")) {
    // find selected option within the select box that's changing
    

    Also I’m not sure but on Chrome I had to use .change instead of .click.

    Lastly, on a personal note, when fading in it might serve a better UI experience if you also fade out – now it disappears immediately. Just an idea 🙂

    http://jsfiddle.net/Dd2YM/1/

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

Sidebar

Related Questions

Currently I have this JQuery script var img = $(this); img.wrap('<div class=photo></div>'); img.parent().append(<p> +
I have this jquery script: $('[id^=changesetList] tr').each(function () { var sid = $(this).attr('sid'); $(this).find('td
I have a partial view with this jquery script: $(#btnGetEmpInfo).click(function () { var selectedItem
I have this jQuery code: <script type=text/javascript > $(function() { $('#add_comment').bind('submit',function() //$(input[type=submit]).click(function() { var
I have this jquery script which suppose to hide/show div element base on the
I have this at the top of my jQuery script: $().ajaxStart(function() { alert('ok'); });
I have this simple function: <script type=text/javascript> //<![CDATA[ jQuery(function($){ function here(b){alert(b);} ; here(6); });
I have this html code <html> <head> <title>JQuery Problem 2</title> <script type=text/javascript src=jquery-1.4.min.js></script> <script
I have this jQuery script I'm trying to implement om Magento and I've tried
so I have this jQuery script below that works. But since I'm just learning

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.