Can I use alert box in return statement?











up vote
0
down vote

favorite












This is my code:






function myFunction() {
var name = document.getElementById('myname').value;
var phone = document.getElementById('myphone').value;
var country = document.getElementById('mycountry').value;
var mail = document.getElementById('mymail').value;
return alert(name + " , " + phone + " , " + country + " , " + mail);
}

<div>
Name<input type="text" id="myname"><br> Phone
<input type="text" id="myphone"><br> Country <input type="text" id="mycontry"><br> Mail
<input type="text" id="mymail"><br>

<button onclick="myFunction()">Try it</button>
</div>





If yes, why don't I get expected result? Can anyone please see my code and correct me?










share|improve this question
























  • alert is a browser's way to notify user of something. It does not return anything
    – Rajesh
    Nov 8 at 9:14










  • Please explain more of what you are trying to do, and perhaps more of your code and we might be able to help. As a guess, try to return alert(name + " , " + phone + " , " + country + " , " + mail);, then you could run alert(myFunction());
    – Tim Rooke
    Nov 8 at 9:29












  • alert() does not return anything. I guess you could say that it returns undefined
    – marvinIsSacul
    Nov 8 at 9:35










  • Firstly thanks a lot.
    – user10493493
    Nov 9 at 5:28










  • Actually I have to read user registrations details and show them in alert box.
    – user10493493
    Nov 9 at 6:14















up vote
0
down vote

favorite












This is my code:






function myFunction() {
var name = document.getElementById('myname').value;
var phone = document.getElementById('myphone').value;
var country = document.getElementById('mycountry').value;
var mail = document.getElementById('mymail').value;
return alert(name + " , " + phone + " , " + country + " , " + mail);
}

<div>
Name<input type="text" id="myname"><br> Phone
<input type="text" id="myphone"><br> Country <input type="text" id="mycontry"><br> Mail
<input type="text" id="mymail"><br>

<button onclick="myFunction()">Try it</button>
</div>





If yes, why don't I get expected result? Can anyone please see my code and correct me?










share|improve this question
























  • alert is a browser's way to notify user of something. It does not return anything
    – Rajesh
    Nov 8 at 9:14










  • Please explain more of what you are trying to do, and perhaps more of your code and we might be able to help. As a guess, try to return alert(name + " , " + phone + " , " + country + " , " + mail);, then you could run alert(myFunction());
    – Tim Rooke
    Nov 8 at 9:29












  • alert() does not return anything. I guess you could say that it returns undefined
    – marvinIsSacul
    Nov 8 at 9:35










  • Firstly thanks a lot.
    – user10493493
    Nov 9 at 5:28










  • Actually I have to read user registrations details and show them in alert box.
    – user10493493
    Nov 9 at 6:14













up vote
0
down vote

favorite









up vote
0
down vote

favorite











This is my code:






function myFunction() {
var name = document.getElementById('myname').value;
var phone = document.getElementById('myphone').value;
var country = document.getElementById('mycountry').value;
var mail = document.getElementById('mymail').value;
return alert(name + " , " + phone + " , " + country + " , " + mail);
}

<div>
Name<input type="text" id="myname"><br> Phone
<input type="text" id="myphone"><br> Country <input type="text" id="mycontry"><br> Mail
<input type="text" id="mymail"><br>

<button onclick="myFunction()">Try it</button>
</div>





If yes, why don't I get expected result? Can anyone please see my code and correct me?










share|improve this question















This is my code:






function myFunction() {
var name = document.getElementById('myname').value;
var phone = document.getElementById('myphone').value;
var country = document.getElementById('mycountry').value;
var mail = document.getElementById('mymail').value;
return alert(name + " , " + phone + " , " + country + " , " + mail);
}

<div>
Name<input type="text" id="myname"><br> Phone
<input type="text" id="myphone"><br> Country <input type="text" id="mycontry"><br> Mail
<input type="text" id="mymail"><br>

<button onclick="myFunction()">Try it</button>
</div>





If yes, why don't I get expected result? Can anyone please see my code and correct me?






function myFunction() {
var name = document.getElementById('myname').value;
var phone = document.getElementById('myphone').value;
var country = document.getElementById('mycountry').value;
var mail = document.getElementById('mymail').value;
return alert(name + " , " + phone + " , " + country + " , " + mail);
}

<div>
Name<input type="text" id="myname"><br> Phone
<input type="text" id="myphone"><br> Country <input type="text" id="mycontry"><br> Mail
<input type="text" id="mymail"><br>

<button onclick="myFunction()">Try it</button>
</div>





function myFunction() {
var name = document.getElementById('myname').value;
var phone = document.getElementById('myphone').value;
var country = document.getElementById('mycountry').value;
var mail = document.getElementById('mymail').value;
return alert(name + " , " + phone + " , " + country + " , " + mail);
}

<div>
Name<input type="text" id="myname"><br> Phone
<input type="text" id="myphone"><br> Country <input type="text" id="mycontry"><br> Mail
<input type="text" id="mymail"><br>

<button onclick="myFunction()">Try it</button>
</div>






javascript






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 9 at 7:53









barbsan

2,1481022




2,1481022










asked Nov 8 at 9:10









user10493493

35




35












  • alert is a browser's way to notify user of something. It does not return anything
    – Rajesh
    Nov 8 at 9:14










  • Please explain more of what you are trying to do, and perhaps more of your code and we might be able to help. As a guess, try to return alert(name + " , " + phone + " , " + country + " , " + mail);, then you could run alert(myFunction());
    – Tim Rooke
    Nov 8 at 9:29












  • alert() does not return anything. I guess you could say that it returns undefined
    – marvinIsSacul
    Nov 8 at 9:35










  • Firstly thanks a lot.
    – user10493493
    Nov 9 at 5:28










  • Actually I have to read user registrations details and show them in alert box.
    – user10493493
    Nov 9 at 6:14


















  • alert is a browser's way to notify user of something. It does not return anything
    – Rajesh
    Nov 8 at 9:14










  • Please explain more of what you are trying to do, and perhaps more of your code and we might be able to help. As a guess, try to return alert(name + " , " + phone + " , " + country + " , " + mail);, then you could run alert(myFunction());
    – Tim Rooke
    Nov 8 at 9:29












  • alert() does not return anything. I guess you could say that it returns undefined
    – marvinIsSacul
    Nov 8 at 9:35










  • Firstly thanks a lot.
    – user10493493
    Nov 9 at 5:28










  • Actually I have to read user registrations details and show them in alert box.
    – user10493493
    Nov 9 at 6:14
















alert is a browser's way to notify user of something. It does not return anything
– Rajesh
Nov 8 at 9:14




alert is a browser's way to notify user of something. It does not return anything
– Rajesh
Nov 8 at 9:14












Please explain more of what you are trying to do, and perhaps more of your code and we might be able to help. As a guess, try to return alert(name + " , " + phone + " , " + country + " , " + mail);, then you could run alert(myFunction());
– Tim Rooke
Nov 8 at 9:29






Please explain more of what you are trying to do, and perhaps more of your code and we might be able to help. As a guess, try to return alert(name + " , " + phone + " , " + country + " , " + mail);, then you could run alert(myFunction());
– Tim Rooke
Nov 8 at 9:29














alert() does not return anything. I guess you could say that it returns undefined
– marvinIsSacul
Nov 8 at 9:35




alert() does not return anything. I guess you could say that it returns undefined
– marvinIsSacul
Nov 8 at 9:35












Firstly thanks a lot.
– user10493493
Nov 9 at 5:28




Firstly thanks a lot.
– user10493493
Nov 9 at 5:28












Actually I have to read user registrations details and show them in alert box.
– user10493493
Nov 9 at 6:14




Actually I have to read user registrations details and show them in alert box.
– user10493493
Nov 9 at 6:14












3 Answers
3






active

oldest

votes

















up vote
0
down vote



accepted










Here is your working code. You were selecting the wrong id:



change <input type="text" id="mycontry" /> to id="mycountry"






function myFunction() {
var name = document.getElementById('myname').value;
var phone = document.getElementById('myphone').value;
var country = document.getElementById('mycountry').value;
var mail = document.getElementById('mymail').value;

//var phone = document.getElementById('myphone').value;
//var country = document.getElementById('mycountry').value;
//var mail = document.getElementById('mymail').value;
return alert(name + " , " + phone + " , " + country + " , " + mail);
}

<div>
Name <input type="text" id="myname" ><br>
Phone <input type="text" id="myphone" ><br>
Country <input type="text" id="mycountry"><br>
Mail <input type="text" id="mymail" value=""><br>

<button onclick="myFunction()">Try it</button>
</div>








share|improve this answer




























    up vote
    0
    down vote













    If you want to use, you can use return with alert() function. But, you cannot get any field's value from alert(). If you want to get fields value from myFunction(). You have to create objects.
    e.g.



    //create constructor

    function myFunction(myname, myphone, mycountry, mymail) {
    this.name = myname;
    this.phone = myphone;
    this.country = mycountry;
    this.mail = mymail;
    }

    //create object

    var obj = new myFunction("testName", "testPhone", "testCountry", "testMail");

    window.onload = alert(obj.name + " , " + obj.phone + " , " + obj.country + " , " + obj.mail);


    About JavaScript - object's functions referencing its fields






    share|improve this answer























    • It is not working. Actually I have to do this :-Read user registration details and show them in an alert box.
      – user10493493
      Nov 9 at 7:12


















    up vote
    0
    down vote













    You don't have to return anything since you're not using return value anywhere. You can just alert:






    function myFunction() {
    var name = document.getElementById('myname').value;
    var phone = document.getElementById('myphone').value;
    var country = document.getElementById('mycountry').value;
    var mail = document.getElementById('mymail').value;
    alert(name + " , " + phone + " , " + country + " , " + mail);
    }

    <div>
    Name
    <input type="text" id="myname"><br>
    Phone
    <input type="text" id="myphone"><br>
    Country
    <input type="text" id="mycountry"><br>
    Mail
    <input type="text" id="mymail"><br>

    <button onclick="myFunction()">Try it</button>
    </div>





    Notice that your actual problem was with country field: (your current code throws an error sating cannot read property value of null since the selected id is wrong)



      <input type="text" id="mycountry">
    <!-- was missing u in here ^^ -->





    share|improve this answer





















      Your Answer






      StackExchange.ifUsing("editor", function () {
      StackExchange.using("externalEditor", function () {
      StackExchange.using("snippets", function () {
      StackExchange.snippets.init();
      });
      });
      }, "code-snippets");

      StackExchange.ready(function() {
      var channelOptions = {
      tags: "".split(" "),
      id: "1"
      };
      initTagRenderer("".split(" "), "".split(" "), channelOptions);

      StackExchange.using("externalEditor", function() {
      // Have to fire editor after snippets, if snippets enabled
      if (StackExchange.settings.snippets.snippetsEnabled) {
      StackExchange.using("snippets", function() {
      createEditor();
      });
      }
      else {
      createEditor();
      }
      });

      function createEditor() {
      StackExchange.prepareEditor({
      heartbeatType: 'answer',
      convertImagesToLinks: true,
      noModals: true,
      showLowRepImageUploadWarning: true,
      reputationToPostImages: 10,
      bindNavPrevention: true,
      postfix: "",
      imageUploader: {
      brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
      contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
      allowUrls: true
      },
      onDemand: true,
      discardSelector: ".discard-answer"
      ,immediatelyShowMarkdownHelp:true
      });


      }
      });














      draft saved

      draft discarded


















      StackExchange.ready(
      function () {
      StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53204548%2fcan-i-use-alert-box-in-return-statement%23new-answer', 'question_page');
      }
      );

      Post as a guest















      Required, but never shown

























      3 Answers
      3






      active

      oldest

      votes








      3 Answers
      3






      active

      oldest

      votes









      active

      oldest

      votes






      active

      oldest

      votes








      up vote
      0
      down vote



      accepted










      Here is your working code. You were selecting the wrong id:



      change <input type="text" id="mycontry" /> to id="mycountry"






      function myFunction() {
      var name = document.getElementById('myname').value;
      var phone = document.getElementById('myphone').value;
      var country = document.getElementById('mycountry').value;
      var mail = document.getElementById('mymail').value;

      //var phone = document.getElementById('myphone').value;
      //var country = document.getElementById('mycountry').value;
      //var mail = document.getElementById('mymail').value;
      return alert(name + " , " + phone + " , " + country + " , " + mail);
      }

      <div>
      Name <input type="text" id="myname" ><br>
      Phone <input type="text" id="myphone" ><br>
      Country <input type="text" id="mycountry"><br>
      Mail <input type="text" id="mymail" value=""><br>

      <button onclick="myFunction()">Try it</button>
      </div>








      share|improve this answer

























        up vote
        0
        down vote



        accepted










        Here is your working code. You were selecting the wrong id:



        change <input type="text" id="mycontry" /> to id="mycountry"






        function myFunction() {
        var name = document.getElementById('myname').value;
        var phone = document.getElementById('myphone').value;
        var country = document.getElementById('mycountry').value;
        var mail = document.getElementById('mymail').value;

        //var phone = document.getElementById('myphone').value;
        //var country = document.getElementById('mycountry').value;
        //var mail = document.getElementById('mymail').value;
        return alert(name + " , " + phone + " , " + country + " , " + mail);
        }

        <div>
        Name <input type="text" id="myname" ><br>
        Phone <input type="text" id="myphone" ><br>
        Country <input type="text" id="mycountry"><br>
        Mail <input type="text" id="mymail" value=""><br>

        <button onclick="myFunction()">Try it</button>
        </div>








        share|improve this answer























          up vote
          0
          down vote



          accepted







          up vote
          0
          down vote



          accepted






          Here is your working code. You were selecting the wrong id:



          change <input type="text" id="mycontry" /> to id="mycountry"






          function myFunction() {
          var name = document.getElementById('myname').value;
          var phone = document.getElementById('myphone').value;
          var country = document.getElementById('mycountry').value;
          var mail = document.getElementById('mymail').value;

          //var phone = document.getElementById('myphone').value;
          //var country = document.getElementById('mycountry').value;
          //var mail = document.getElementById('mymail').value;
          return alert(name + " , " + phone + " , " + country + " , " + mail);
          }

          <div>
          Name <input type="text" id="myname" ><br>
          Phone <input type="text" id="myphone" ><br>
          Country <input type="text" id="mycountry"><br>
          Mail <input type="text" id="mymail" value=""><br>

          <button onclick="myFunction()">Try it</button>
          </div>








          share|improve this answer












          Here is your working code. You were selecting the wrong id:



          change <input type="text" id="mycontry" /> to id="mycountry"






          function myFunction() {
          var name = document.getElementById('myname').value;
          var phone = document.getElementById('myphone').value;
          var country = document.getElementById('mycountry').value;
          var mail = document.getElementById('mymail').value;

          //var phone = document.getElementById('myphone').value;
          //var country = document.getElementById('mycountry').value;
          //var mail = document.getElementById('mymail').value;
          return alert(name + " , " + phone + " , " + country + " , " + mail);
          }

          <div>
          Name <input type="text" id="myname" ><br>
          Phone <input type="text" id="myphone" ><br>
          Country <input type="text" id="mycountry"><br>
          Mail <input type="text" id="mymail" value=""><br>

          <button onclick="myFunction()">Try it</button>
          </div>








          function myFunction() {
          var name = document.getElementById('myname').value;
          var phone = document.getElementById('myphone').value;
          var country = document.getElementById('mycountry').value;
          var mail = document.getElementById('mymail').value;

          //var phone = document.getElementById('myphone').value;
          //var country = document.getElementById('mycountry').value;
          //var mail = document.getElementById('mymail').value;
          return alert(name + " , " + phone + " , " + country + " , " + mail);
          }

          <div>
          Name <input type="text" id="myname" ><br>
          Phone <input type="text" id="myphone" ><br>
          Country <input type="text" id="mycountry"><br>
          Mail <input type="text" id="mymail" value=""><br>

          <button onclick="myFunction()">Try it</button>
          </div>





          function myFunction() {
          var name = document.getElementById('myname').value;
          var phone = document.getElementById('myphone').value;
          var country = document.getElementById('mycountry').value;
          var mail = document.getElementById('mymail').value;

          //var phone = document.getElementById('myphone').value;
          //var country = document.getElementById('mycountry').value;
          //var mail = document.getElementById('mymail').value;
          return alert(name + " , " + phone + " , " + country + " , " + mail);
          }

          <div>
          Name <input type="text" id="myname" ><br>
          Phone <input type="text" id="myphone" ><br>
          Country <input type="text" id="mycountry"><br>
          Mail <input type="text" id="mymail" value=""><br>

          <button onclick="myFunction()">Try it</button>
          </div>






          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Nov 9 at 8:15









          Nelson Owalo

          1,015925




          1,015925
























              up vote
              0
              down vote













              If you want to use, you can use return with alert() function. But, you cannot get any field's value from alert(). If you want to get fields value from myFunction(). You have to create objects.
              e.g.



              //create constructor

              function myFunction(myname, myphone, mycountry, mymail) {
              this.name = myname;
              this.phone = myphone;
              this.country = mycountry;
              this.mail = mymail;
              }

              //create object

              var obj = new myFunction("testName", "testPhone", "testCountry", "testMail");

              window.onload = alert(obj.name + " , " + obj.phone + " , " + obj.country + " , " + obj.mail);


              About JavaScript - object's functions referencing its fields






              share|improve this answer























              • It is not working. Actually I have to do this :-Read user registration details and show them in an alert box.
                – user10493493
                Nov 9 at 7:12















              up vote
              0
              down vote













              If you want to use, you can use return with alert() function. But, you cannot get any field's value from alert(). If you want to get fields value from myFunction(). You have to create objects.
              e.g.



              //create constructor

              function myFunction(myname, myphone, mycountry, mymail) {
              this.name = myname;
              this.phone = myphone;
              this.country = mycountry;
              this.mail = mymail;
              }

              //create object

              var obj = new myFunction("testName", "testPhone", "testCountry", "testMail");

              window.onload = alert(obj.name + " , " + obj.phone + " , " + obj.country + " , " + obj.mail);


              About JavaScript - object's functions referencing its fields






              share|improve this answer























              • It is not working. Actually I have to do this :-Read user registration details and show them in an alert box.
                – user10493493
                Nov 9 at 7:12













              up vote
              0
              down vote










              up vote
              0
              down vote









              If you want to use, you can use return with alert() function. But, you cannot get any field's value from alert(). If you want to get fields value from myFunction(). You have to create objects.
              e.g.



              //create constructor

              function myFunction(myname, myphone, mycountry, mymail) {
              this.name = myname;
              this.phone = myphone;
              this.country = mycountry;
              this.mail = mymail;
              }

              //create object

              var obj = new myFunction("testName", "testPhone", "testCountry", "testMail");

              window.onload = alert(obj.name + " , " + obj.phone + " , " + obj.country + " , " + obj.mail);


              About JavaScript - object's functions referencing its fields






              share|improve this answer














              If you want to use, you can use return with alert() function. But, you cannot get any field's value from alert(). If you want to get fields value from myFunction(). You have to create objects.
              e.g.



              //create constructor

              function myFunction(myname, myphone, mycountry, mymail) {
              this.name = myname;
              this.phone = myphone;
              this.country = mycountry;
              this.mail = mymail;
              }

              //create object

              var obj = new myFunction("testName", "testPhone", "testCountry", "testMail");

              window.onload = alert(obj.name + " , " + obj.phone + " , " + obj.country + " , " + obj.mail);


              About JavaScript - object's functions referencing its fields







              share|improve this answer














              share|improve this answer



              share|improve this answer








              edited Nov 8 at 10:13

























              answered Nov 8 at 10:02









              Alice

              6771820




              6771820












              • It is not working. Actually I have to do this :-Read user registration details and show them in an alert box.
                – user10493493
                Nov 9 at 7:12


















              • It is not working. Actually I have to do this :-Read user registration details and show them in an alert box.
                – user10493493
                Nov 9 at 7:12
















              It is not working. Actually I have to do this :-Read user registration details and show them in an alert box.
              – user10493493
              Nov 9 at 7:12




              It is not working. Actually I have to do this :-Read user registration details and show them in an alert box.
              – user10493493
              Nov 9 at 7:12










              up vote
              0
              down vote













              You don't have to return anything since you're not using return value anywhere. You can just alert:






              function myFunction() {
              var name = document.getElementById('myname').value;
              var phone = document.getElementById('myphone').value;
              var country = document.getElementById('mycountry').value;
              var mail = document.getElementById('mymail').value;
              alert(name + " , " + phone + " , " + country + " , " + mail);
              }

              <div>
              Name
              <input type="text" id="myname"><br>
              Phone
              <input type="text" id="myphone"><br>
              Country
              <input type="text" id="mycountry"><br>
              Mail
              <input type="text" id="mymail"><br>

              <button onclick="myFunction()">Try it</button>
              </div>





              Notice that your actual problem was with country field: (your current code throws an error sating cannot read property value of null since the selected id is wrong)



                <input type="text" id="mycountry">
              <!-- was missing u in here ^^ -->





              share|improve this answer

























                up vote
                0
                down vote













                You don't have to return anything since you're not using return value anywhere. You can just alert:






                function myFunction() {
                var name = document.getElementById('myname').value;
                var phone = document.getElementById('myphone').value;
                var country = document.getElementById('mycountry').value;
                var mail = document.getElementById('mymail').value;
                alert(name + " , " + phone + " , " + country + " , " + mail);
                }

                <div>
                Name
                <input type="text" id="myname"><br>
                Phone
                <input type="text" id="myphone"><br>
                Country
                <input type="text" id="mycountry"><br>
                Mail
                <input type="text" id="mymail"><br>

                <button onclick="myFunction()">Try it</button>
                </div>





                Notice that your actual problem was with country field: (your current code throws an error sating cannot read property value of null since the selected id is wrong)



                  <input type="text" id="mycountry">
                <!-- was missing u in here ^^ -->





                share|improve this answer























                  up vote
                  0
                  down vote










                  up vote
                  0
                  down vote









                  You don't have to return anything since you're not using return value anywhere. You can just alert:






                  function myFunction() {
                  var name = document.getElementById('myname').value;
                  var phone = document.getElementById('myphone').value;
                  var country = document.getElementById('mycountry').value;
                  var mail = document.getElementById('mymail').value;
                  alert(name + " , " + phone + " , " + country + " , " + mail);
                  }

                  <div>
                  Name
                  <input type="text" id="myname"><br>
                  Phone
                  <input type="text" id="myphone"><br>
                  Country
                  <input type="text" id="mycountry"><br>
                  Mail
                  <input type="text" id="mymail"><br>

                  <button onclick="myFunction()">Try it</button>
                  </div>





                  Notice that your actual problem was with country field: (your current code throws an error sating cannot read property value of null since the selected id is wrong)



                    <input type="text" id="mycountry">
                  <!-- was missing u in here ^^ -->





                  share|improve this answer












                  You don't have to return anything since you're not using return value anywhere. You can just alert:






                  function myFunction() {
                  var name = document.getElementById('myname').value;
                  var phone = document.getElementById('myphone').value;
                  var country = document.getElementById('mycountry').value;
                  var mail = document.getElementById('mymail').value;
                  alert(name + " , " + phone + " , " + country + " , " + mail);
                  }

                  <div>
                  Name
                  <input type="text" id="myname"><br>
                  Phone
                  <input type="text" id="myphone"><br>
                  Country
                  <input type="text" id="mycountry"><br>
                  Mail
                  <input type="text" id="mymail"><br>

                  <button onclick="myFunction()">Try it</button>
                  </div>





                  Notice that your actual problem was with country field: (your current code throws an error sating cannot read property value of null since the selected id is wrong)



                    <input type="text" id="mycountry">
                  <!-- was missing u in here ^^ -->





                  function myFunction() {
                  var name = document.getElementById('myname').value;
                  var phone = document.getElementById('myphone').value;
                  var country = document.getElementById('mycountry').value;
                  var mail = document.getElementById('mymail').value;
                  alert(name + " , " + phone + " , " + country + " , " + mail);
                  }

                  <div>
                  Name
                  <input type="text" id="myname"><br>
                  Phone
                  <input type="text" id="myphone"><br>
                  Country
                  <input type="text" id="mycountry"><br>
                  Mail
                  <input type="text" id="mymail"><br>

                  <button onclick="myFunction()">Try it</button>
                  </div>





                  function myFunction() {
                  var name = document.getElementById('myname').value;
                  var phone = document.getElementById('myphone').value;
                  var country = document.getElementById('mycountry').value;
                  var mail = document.getElementById('mymail').value;
                  alert(name + " , " + phone + " , " + country + " , " + mail);
                  }

                  <div>
                  Name
                  <input type="text" id="myname"><br>
                  Phone
                  <input type="text" id="myphone"><br>
                  Country
                  <input type="text" id="mycountry"><br>
                  Mail
                  <input type="text" id="mymail"><br>

                  <button onclick="myFunction()">Try it</button>
                  </div>






                  share|improve this answer












                  share|improve this answer



                  share|improve this answer










                  answered Nov 9 at 8:18









                  Bhojendra Rauniyar

                  50.1k1978121




                  50.1k1978121






























                      draft saved

                      draft discarded




















































                      Thanks for contributing an answer to Stack Overflow!


                      • Please be sure to answer the question. Provide details and share your research!

                      But avoid



                      • Asking for help, clarification, or responding to other answers.

                      • Making statements based on opinion; back them up with references or personal experience.


                      To learn more, see our tips on writing great answers.





                      Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


                      Please pay close attention to the following guidance:


                      • Please be sure to answer the question. Provide details and share your research!

                      But avoid



                      • Asking for help, clarification, or responding to other answers.

                      • Making statements based on opinion; back them up with references or personal experience.


                      To learn more, see our tips on writing great answers.




                      draft saved


                      draft discarded














                      StackExchange.ready(
                      function () {
                      StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53204548%2fcan-i-use-alert-box-in-return-statement%23new-answer', 'question_page');
                      }
                      );

                      Post as a guest















                      Required, but never shown





















































                      Required, but never shown














                      Required, but never shown












                      Required, but never shown







                      Required, but never shown

































                      Required, but never shown














                      Required, but never shown












                      Required, but never shown







                      Required, but never shown







                      這個網誌中的熱門文章

                      Tangent Lines Diagram Along Smooth Curve

                      Yusuf al-Mu'taman ibn Hud

                      Zucchini