Monday, May 20, 2024
 Popular · Latest · Hot · Upcoming
78
rated 0 times [  81] [ 3]  / answers: 1 / hits: 19766  / 7 Years ago, tue, august 29, 2017, 12:00:00

I want to get the text of the input text field on click of the go button. I have read a few tutorials on this, followed them step by step, but still failed to do so. Here is my code :





function go() {
content.html($(#textfield).value);
}

<!DOCTYPE html>
<html>

<head></head>

<body>
<div id=content>
<input type=text id=textfield>
<button type=button id=btn onclick=go()>Go</button>
</div>
<script type=text/javascript src=https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js></script>
</body>

</html>





May I ask what is wrong with it?


More From » jquery

 Answers
8

you can use .val() to get value of input.



<script src=https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js></script>

<html>
<head></head>
<body>
<div id=content>
<input type=text id=textfield>
<button type=button id=btn onclick=go()>Go</button>
</div>
<script type=text/javascript src=https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js></script>
<script type=text/javascript>
function go()
{
console.log($(#textfield).val());
}
</script>
</body>
</html>




[#56630] Friday, August 25, 2017, 7 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
micayla

Total Points: 148
Total Questions: 92
Total Answers: 109

Location: Aruba
Member since Sat, Oct 2, 2021
3 Years ago
micayla questions
Fri, Dec 24, 21, 00:00, 2 Years ago
Thu, Apr 16, 20, 00:00, 4 Years ago
Thu, Nov 14, 19, 00:00, 5 Years ago
;