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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T12:01:34+00:00 2026-05-15T12:01:34+00:00

I have a form, like so: <form action= method=post> <select name=pageType> <option value=main>Main Page</option>

  • 0

I have a form, like so:

<form action="" method="post">
   <select name="pageType">
      <option value="main">Main Page</option>
      <option value="sub">Sub Page</option>
      <option value="sub-sub">Sub-Sub Page</option>
   </select>

<br />

<label>Choose Sub Sub Name:</label> <input type="text" name="sub-sub-name" />

<br />

<input type="submit" name="submit" value="GO!" />

</form>

What I would like to achive is for this text field (and it’s label):

<label>Choose Sub Sub Name:</label> <input type="text" name="sub-sub-name" />

to only appear if the 3rd option (sub sub page) is selected from the drop down and not show up otherwise. How can this be done with either javascript or the jquery framework?

EDIT

by the way, it would be nice if this can be achieved without the page needing to refresh and losing previously submitted form data. I know form data can still be kept using variables that store the values even on page refresh, but I was hoping for that effect that I see on a lot of sites where the additional text area (or other form element) just appears without page refresh.

  • 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-15T12:01:35+00:00Added an answer on May 15, 2026 at 12:01 pm

    Hiding/showing the label and the field is easy. Put the field in the label (which associates them), give the label style="display: none", and give it an ID. E.g.:

    <label id='thirdField' style='display: none'>Choose Sub Sub Name: <input type="text" name="sub-sub-name" /></label>
    

    Then you can show it via show

    $("#thirdField").show();
    

    …and hide it via hide:

    $("#thirdField").hide();
    

    …or (and it’s not hyper-clear from the docs, but if you get to the bottom of the page you’ll find it) you can toggle based on a boolean value using toggle:

    $("#thirdField").toggle(true); // true to show, false to hide
    

    So now what you need is a trigger that fires when the third option in the select is chosen. There’s the change event, but it doesn’t fire until the focus leaves the select field. (jQuery normalizes that; otherwise, when it fired would be browser-dependent.) You could try click on the option itself, but I don’t know if it’s reliable when navigation is via the keyboard.

    To be proactive (which is particularly important if the field you’re showing immediately follows the select box in the tab order!), I tend to use a timer to watch for changes (an idea I got from the Prototype guys, they have a whole class for this):

    var selectField = $("#mySelectField");
    var thirdField = $("#thirdField");
    var handle = setInterval(watchForChange, 250); // Every quarter second
    function watchForChange() {
        thirdField.toggle(selectField.val() === "sub-sub");
    }
    

    (There I assume you’ve given the id mySelectField to your select field.) When you don’t need to do this anymore, you want to cancel the interval:

    clearInterval(handle);
    handle = 0;
    

    Naturally you wouldn’t do all of the above at the top level, that would itnroduce a bunch of global variables. You’d put it inside a scoping function.

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

Sidebar

Related Questions

I have form like this: <form method=POST action=<?php echo base_url() ?>admin/admin_search> <fieldset> <label for=nalozi>Nalozi</label><input
I have a simple form like this: <form name=serachForm method=post action=/home/search> <input type=text name=searchText
I have a form like this: <form id=loginCompact action=https://externalsite... name=sportsbook method=post onsubmit=createCookie('BRLOG', document.sportsbook.username.value, 1)>
I have regular form like this. <form action=/domainchecker.php method=post> <input type=text name=domain size=20> <fieldset>
I have a form like this: <form method=post action=> <?php $h = mysql_query(select distinct
I have a form to upload image like below <form name=sample enctype=multipart/form-data action=index.php method=post
I have an HTML form that looks like this: <form action=index.php method=post> <input type=hidden
I am testing a form. It looks like: <form accept-charset=UTF-8 action=/the_action method=post> <select id=id
I have an input form for a sample php. <form action=insert.php method=post> <table> <tr>
I have simple form like this which accepts only two values string action and

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.