0

I have a button on my page which executes a JavaScript function on click. Now I have a variable in my function whose value should be the one which user enters in input text box. Here is my code.

    <input type="text"> </input>
    <button id ="buttton" class="button" onclick="myfunction()">Create Envelope</button>

    <script>
    function myfunction() {
    var sub =""; // I am thinking of writing jquery 
}
   </script>

Now by the time user clicks the button my variable sub should hold the value which user enters in the input field.

0

1 Answer 1

3

Use .value property of InputElement(JavaScript) or $(ELEMENT).val() method of jQuery

To select the element, give unique ID to element. There are other ways to select the element as well which are class-selector or attribute-selector and many more!

function myfunction() {
  var sub = $('#input').val();
  console.log(sub);
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.min.js"></script>
<input type="text" id='input'>
<button id="buttton" class="button" onclick="myfunction()">Create Envelope</button>

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

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.