2

I have 2 <div>

<div id="form">
    <form id="myform">
         <input type="text" id="value1"/>
         <input type="submit" value="Submit"/>
    </form>
</div>

<div id="display">
    <!--- value1 to be displayed here -->
</div>

I need to do this all in 1 file (no php or jsp).

Any ideas?

1 Answer 1

2

You can do it by setting event listener on input field and writing value of that field inside div
Check example snippet below

$('#value1').on('input', function() {
  $('#display').text($(this).val());


});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div id="form">
  <form id="myform">
    <input type="text" id="value1" />
    <input type="submit" value="Submit" />
  </form>
</div>

<div id="display">
  <!--- value1 to be displayed here -->
</div>

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

2 Comments

if I had 12 "text" inputs - would you do the same thing but put some <br/> between each?
I would make different <p> inside this div for each input, so it would be easier to collect/style text

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.