2

I'm having this problem where I can't seem to figure out how to show my (filled in) form in a jquery alert. Under my code is a standard form in HTML nothing wrong there all id's are named what you can see in the .val().

<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
<script>
    $(document).ready(function() {
      var name = $("#name").val();
      console.log(name);
      $('#form').submit(function() {
        $('#progress').show();
        alert (" Formulier: " + $("#form input").val(name, email, number, comment));
      });
    });
</script>
<style>
    #progress {
      display: none;
      color: green;
    }
</style>

Ivan
  • 34,531
  • 8
  • 55
  • 100
Jos Bakker
  • 23
  • 4
  • You are not reading the input values correctly. Possible duplicate of [Get the value in an input text box](https://stackoverflow.com/questions/4088467/get-the-value-in-an-input-text-box). And FYI, there is no such thing as a _"jQuery alert"_. – Turnip Sep 07 '17 at 11:33
  • 1
    `$("#form input").val(name, email, number, comment)` - what is that supposed to achieve? Did you find such a syntax for .val() documented anywhere ... or are you just inventing your own here? – CBroe Sep 07 '17 at 11:34
  • I really don't know I knew that part was wrong but still it's not working I'm new to jquery – Jos Bakker Sep 07 '17 at 11:36
  • 1
    It's not really clear from that line of code what you're even *trying* to do. Are you just trying to show a single alert box with all of the values which are currently in the form? Are you able to do this with *one* value, and try to expand from there? – David Sep 07 '17 at 11:41

1 Answers1

1

You can get all form values with serialize() method.

alert (" Formulier: " + $("#form input").serialize());
SilverSurfer
  • 4,281
  • 6
  • 24
  • 50