Skip to content
Advertisements

JQuery When Done Examples

Example 1

when-done example
<div class="container">
        <input type="text" id="uName" class="row m-2 form-control text-center" placeholder="name">
        <input type="text" id="uSurname" class="row m-2 form-control text-center" placeholder="surname">
        <input type="text" id="uAge" class="row m-2 form-control text-center" placeholder="age">
        <button id="but" class="btn btn-danger btn-block">Click</button>
        <div id="result" class="form-block text-center mt-4"></div>
    </div>

<script>

    $(document).ready(function(){

      function card() {
        let uName = $("#uName").val();
        let uSurname = $("#uSurname").val();
        let uAge = $("#uAge").val();
          $.when(
          {name: uName},
          {surname: uSurname},
          {age: uAge}
        ).done(function(tName,tSurname,tAge){
          $("#result").html(
            "Name: " + tName.name + "<br>" +
            "Surname: " + tSurname.surname + "<br>" +
            "Age: " + tAge.age 
          )
        })
      }
      $("button").click(card)
      $(".container").keyup(function(e){
          if(e.keyCode == 13){
              card();
          }
      })  

    })

</script>

Example 2

    <div class="container">
        <div id="result" class="form-block text-center mt-4"></div>
    </div>

  <script>


    $(document).ready(function(){
        let days = Array("monday","thuesday","wednesday","thursday","friday");
        let rows = "";
        $.each(days,function(row,content){
            rows += "Row: " + row + "<br>"  + "Day: " + content + "<br>" + "<br>"
        })
        $("#result").html(rows);
    })
    

  </script>
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.

%d bloggers like this: