0

Good day, I just want to know how do you print out the value you entered on the text field via alert box, I'm new to jquery and I don't have any idea what am I doing. Any help would be appreciated. Thank you

             <form action="" align="center" method="post">
             Name:<br>
             <input type="text" name="fullname" required>
             <input type="submit" onclick="printOut();">
             </form>


             $(document).ready(function(){
             $('form').submit(function(e){
             e.printOut();


            alert ("Hi "+$("input[name="fullname"]").val()+");
user3396187
  • 63
  • 1
  • 5
  • 15
  • 1
    Possible duplicate of [Get the value in an input text box](https://stackoverflow.com/questions/4088467/get-the-value-in-an-input-text-box) – messerbill Mar 06 '18 at 14:53
  • 1
    If you don't know what you are doing, then open this page: https://developer.mozilla.org/en-US/docs/Learn/Getting_started_with_the_web/JavaScript_basics – dfsq Mar 06 '18 at 14:53

3 Answers3

1

The error is in your JQuery selector, the unescaped quotes inside of your string is breaking the syntax. Try this:

$(document).ready(function(){
    $('form').submit(function(e){
        alert ("Hi "+$("input[name='fullname']").val());
        return false;
    });
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<form align="center">
    Name:<br />
    <input type="text" name="fullname" required />
    <input type="submit" />
</form>
Matthew Schlachter
  • 3,250
  • 1
  • 12
  • 26
0

you are using the wrong css $("input[name="fullname"]")selector everything else is okay it should be $("input[name=fullname]")

try this code

 <form action="" align="center" method="post">
         Name:<br>
         <input type="text" name="fullname" required>
         <input type="submit" onclick="printOut();">
  </form>

  <script>
         $(document).ready(function(){
         $('form').submit(function(e){
          e.preventDefault();

        alert ("Hi "+$("input[name="fullname"]").val()+");
 </script>
QaMar ALi
  • 229
  • 2
  • 12
0

Try something like this:

 <form action="" align="center" method="post">
                 Name:<br>
                 <input type="text" name="fullname" required>
                 <input type="submit"">
 </form>

<script>
    $('form').submit(function(e){
        e.preventDefault();
        alert("Hi "+ $("input[name='fullname']").val());
    });

</script>
Dzanan Begovic
  • 160
  • 1
  • 8