0

I have implemented a coding to show a text-box when the user clicks a button. I need to modify that coding to view 2 text-boxes when user clicks that same button. I'll put the coding down below. Thanks!

  <div class="form-group">
    <div class="col-sm-9">
  <div id="welcomeDiv"  class="answer_list" style="display:none;">  <input type="text" /></div>

  <input type="button" name="answer" value="Customize Size" onclick="showDiv()" />

</div>

function showDiv(){
      $( "#welcomeDiv" ).show( "slow" );
}
1
  • This isn't PHP, it's javascript. Anyway, the solution is to change your div id to a class and assign that class to both divs Commented Sep 27, 2017 at 0:11

2 Answers 2

1

Try this one .

 <!DOCTYPE html>
    <html>
    <head>
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
    <script>
    $(document).ready(function(){
     $("#input1").hide();
             $("#input2").hide();
        $("#hide").click(function(){
            $("#input1").hide();
             $("#input2").hide();
        });
        $("#show").click(function(){
            $("#input1").show();
             $("#input2").show();
        });
    });
    </script>
    </head>
    <body>

    <input type="text" id="input1"/>
    <input type="text" id="input2"/>

    <button id="hide">Hide</button>
    <button id="show">Show</button>

    </body>
    </html>

Hope this help :)

Sign up to request clarification or add additional context in comments.

Comments

0

this is exactly same like your code check this out this is fiddle link and with code snippet also

 <div class="form-group">
    <div class="col-sm-9">
  <div id="welcomeDiv"  class="answer_list">  <input type="text" /></div>
  <input type="button" name="answer" value="Customize Size" />
</div>

this is javascript little bit different but you will get it

$("input[type='button']").click(function(){
      $("#welcomeDiv").show('slow');
});

i dont like to give style in elements so use css.css

#welcomeDiv{
  display:none;
}

$("input[type='button']").click(function(){
      $("#welcomeDiv").show('slow');
});
#welcomeDiv{
  display:none;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div class="form-group">
    <div class="col-sm-9">
  <div id="welcomeDiv"  class="answer_list">  <input type="text" /></div>
  <input type="button" name="answer" value="Customize Size" />

</div>

1 Comment

Maybe you need click to hide so let me know i will try to help you

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.