Get the value in with Jquery
Now we will see the command .val (). val() allows us to get data from form elements. Normally we get the contents of html elements with text () or html (), but we can not get form elements with them. So we will get the form elements with val () command.
Html and Jquery
- First of all we need the jquery library
2 |
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script> |
- Then add an html to the input text field and set the id
2 |
<p>Site: <input type="text" id="test" value="tahasivaci.com"></p> |
- Let’s write the script code we checked
2 3 4 5 6 |
<script type="text/javascript"> $(document).ready(function(){ alert($("#test").val()); }); </script> |
- The important part here is that we will take the value of the id value that we have in the document ready.
General Code
2 3 4 5 6 7 8 9 10 |
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script> <p>Site: <input type="text" id="test" value="tahasivaci.com"></p> <script type="text/javascript"> $(document).ready(function(){ alert($("#test").val()); }); </script> |
- You can write this code in a html file and open it in a browser.
Run Code
Good luck with 🙂
Recent Comments