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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T23:19:52+00:00 2026-06-06T23:19:52+00:00

I have two input field like this <input type=text class=span3 id name=name > <input

  • 0

I have two input field like this

<input type="text" class="span3" id name="name" >
<input type="text" class="span3" id name="phone" >

<div class="show-example1">
      show content 1
</div>
<div class="show-example2">
      show content 2
</div>

I want to show only div element “show-example1” after click on input field “name”

and show only div element “show-example2” after click on input field “phone”

For this i made two div element associated with each input field.

Below is my script for performing above action

 $('.show-example1').hide();
  $('.show-example2').hide();

$("input[name='name']").bind("click", function(event){

            $('.show-example2').hide();
            $('.show-example1').show(400);
            return false;

        }); 

    $("input[name='phone']").bind("click", function(event){

            $('.show-example1').hide();
            $('.show-example2').show(400);
            return false;

        });

My script is working fine but i just want to know a better way to do above action.

  • 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-06T23:19:54+00:00Added an answer on June 6, 2026 at 11:19 pm

    Here’s my solution. In short – I utilize tag attributes, focus and blur events to take care of this task.
    The benefit of it, compared to others, is that you with few lines of jQuery you can cover all your form elements, without necessity to manually switch every other div on/off, while at the same time keeping the unobtrusive approach of you JS.

    HTML

    <form>
        Other information <textarea name="other_information" class="hintable" hint-class="show-example1"></textarea><br />
        Nationality <textarea name="nationality" class="hintable" hint-class="show-example2"></textarea><br />
        <div class="example show-example1">
            Example 1
        </div>
        <div class="example show-example2">
            Example 2
        </div>
    </form>
    

    CSS

    .example
    {
        display: none;
    }​
    

    JS

    $('.hintable').focus(function() {
       $('.example').hide();
       $("."+$(this).attr('hint-class')).show();
    });
    
    $('.hintable').blur(function() {
       $('.example').hide();
    });
    

    ​

    Fiddle link.

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

Sidebar

Related Questions

I have a form with two input text fields: <input id=ModelName_test_0 name=ModelName[test][0] type=text> <input
I have a form with two text_fields: <input type=text id=post_name name=post[name] /> <input type=text
I have a simple form and inside there are two input fields text type.
I have two sets of of input fields like this, differentiated by their classes:
I have got two input fields which i would like to make editable with
I hope I can explain this right I have two input fields that require
I have an HTML5 Canvas on my page along with two text input fields.
I have two input text boxes which are decimal. The sum of the two
basically I have two input fields, name and username. The idea is that the
I have this code here http://jsfiddle.net/RzBeM/65/ you will see two input fields called quantity.

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.