0

I have a situation like there will be one hidden div

<div id="div_id">
     <input type="text" id="input_id" name="input_name">
</div

I have hidden the div using hide() function using jquery

  $('#div_id').hide();

Now my problem is how can I add values to above input field and display the values when I show the div.

   $(document).ready(function(){
       $("select#po_pos").change(function()
       {
           var stateId = $("#po_pos option:selected").val();
           $('#input_id').val($('#').val() + stateId);
       }
 });

can anyone help on this please??thanks

3
  • on div show you can get value form that input and show in label using jquery Commented Mar 21, 2018 at 6:04
  • Can you please explain what's this code '$('#input_id').val($('#').val() + stateId);'. Commented Mar 21, 2018 at 6:10
  • @vikalp I am trying to append state id to the input box Commented Mar 21, 2018 at 6:15

2 Answers 2

1

You were missing the input box id. This may help you

$(document).ready(function(){
       $("#po_pos").change(function()
       {
           var stateId = $("#po_pos option:selected").val();
           $('#input_id').val($('#input_id').val() + stateId);
       });
       $("#btn1").click(function()
       {
           $('#div_id').show();
       });
       $("#btn2").click(function()
       {
           $('#div_id').hide();
       });
 });
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div id="div_id">
     <input type="text" id="input_id" name="input_name">
</div>
<select id="po_pos">
  <option value="1">Volvo</option>
  <option value="2">Saab</option>
  <option value="3">Mercedes</option>
  <option value="4">Audi</option>
</select>
<input type="button" id="btn1" value="Show"/>
<input type="button" id="btn2" value="Hide"/>

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

Comments

0

I think you are looking for this :

<div id="div_id">
     <input type="text" id="input_id" name="input_name">
</div>

<script>        
  $('#div_id').hide();

   $(document).ready(function(){
       $("select#po_pos").change(function()
       {
           var stateId = $("#po_pos option:selected").val();
           var inputVal = $('#'+stateId).val();
           $('#input_id').val(inputVal);
           $('#div_id').show();
       }
 });
</script>

Comments

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.