What does document.form mean in javascript?












15














In JavaScript, what is the meaning of the identifiers document.cookie, document.forms and the .value field? I have trouble understanding the use of the below syntax example.



var x=document.forms["myForm"]["email"].value


Best wishes😀










share|improve this question




















  • 8




    I am confused. Do you want to know about document.cookie or document.forms?
    – the_drow
    Jan 17 '11 at 15:50






  • 1




    I don't think he/she knows
    – hunter
    Jan 17 '11 at 15:52










  • @the_draw i want to know .value property and document.form function
    – dramasea
    Jan 17 '11 at 15:54






  • 3




    document.forms is not a function. It's an hash table. In fact everything in javascript is a hash table but document.forms is meant to be used as a hash table. And for the love of god improve your English. People need to understand you.
    – the_drow
    Jan 17 '11 at 15:57
















15














In JavaScript, what is the meaning of the identifiers document.cookie, document.forms and the .value field? I have trouble understanding the use of the below syntax example.



var x=document.forms["myForm"]["email"].value


Best wishes😀










share|improve this question




















  • 8




    I am confused. Do you want to know about document.cookie or document.forms?
    – the_drow
    Jan 17 '11 at 15:50






  • 1




    I don't think he/she knows
    – hunter
    Jan 17 '11 at 15:52










  • @the_draw i want to know .value property and document.form function
    – dramasea
    Jan 17 '11 at 15:54






  • 3




    document.forms is not a function. It's an hash table. In fact everything in javascript is a hash table but document.forms is meant to be used as a hash table. And for the love of god improve your English. People need to understand you.
    – the_drow
    Jan 17 '11 at 15:57














15












15








15


5





In JavaScript, what is the meaning of the identifiers document.cookie, document.forms and the .value field? I have trouble understanding the use of the below syntax example.



var x=document.forms["myForm"]["email"].value


Best wishes😀










share|improve this question















In JavaScript, what is the meaning of the identifiers document.cookie, document.forms and the .value field? I have trouble understanding the use of the below syntax example.



var x=document.forms["myForm"]["email"].value


Best wishes😀







javascript forms






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Mar 17 '16 at 6:26









Issa Chanzi

953818




953818










asked Jan 17 '11 at 15:49









dramasea

1,405123660




1,405123660








  • 8




    I am confused. Do you want to know about document.cookie or document.forms?
    – the_drow
    Jan 17 '11 at 15:50






  • 1




    I don't think he/she knows
    – hunter
    Jan 17 '11 at 15:52










  • @the_draw i want to know .value property and document.form function
    – dramasea
    Jan 17 '11 at 15:54






  • 3




    document.forms is not a function. It's an hash table. In fact everything in javascript is a hash table but document.forms is meant to be used as a hash table. And for the love of god improve your English. People need to understand you.
    – the_drow
    Jan 17 '11 at 15:57














  • 8




    I am confused. Do you want to know about document.cookie or document.forms?
    – the_drow
    Jan 17 '11 at 15:50






  • 1




    I don't think he/she knows
    – hunter
    Jan 17 '11 at 15:52










  • @the_draw i want to know .value property and document.form function
    – dramasea
    Jan 17 '11 at 15:54






  • 3




    document.forms is not a function. It's an hash table. In fact everything in javascript is a hash table but document.forms is meant to be used as a hash table. And for the love of god improve your English. People need to understand you.
    – the_drow
    Jan 17 '11 at 15:57








8




8




I am confused. Do you want to know about document.cookie or document.forms?
– the_drow
Jan 17 '11 at 15:50




I am confused. Do you want to know about document.cookie or document.forms?
– the_drow
Jan 17 '11 at 15:50




1




1




I don't think he/she knows
– hunter
Jan 17 '11 at 15:52




I don't think he/she knows
– hunter
Jan 17 '11 at 15:52












@the_draw i want to know .value property and document.form function
– dramasea
Jan 17 '11 at 15:54




@the_draw i want to know .value property and document.form function
– dramasea
Jan 17 '11 at 15:54




3




3




document.forms is not a function. It's an hash table. In fact everything in javascript is a hash table but document.forms is meant to be used as a hash table. And for the love of god improve your English. People need to understand you.
– the_drow
Jan 17 '11 at 15:57




document.forms is not a function. It's an hash table. In fact everything in javascript is a hash table but document.forms is meant to be used as a hash table. And for the love of god improve your English. People need to understand you.
– the_drow
Jan 17 '11 at 15:57












3 Answers
3






active

oldest

votes


















23














document.forms["myForm"]["email"].value



that will get the value of the "email" element within the "myForm" <form>



<form id="myForm" name="myForm">
<input id="email" name="email" value="some@email.com" />
</form>


so x will equal "some@email.com"





document.forms will return a collection of all of the forms within a particular page. writing document.forms["myForm"] will return the form with the name "myForm" from that collection






share|improve this answer



















  • 2




    you had explain the .value property, how about the document.form? Thanks!
    – dramasea
    Jan 17 '11 at 15:56



















13














documents.forms is an object containing all of the forms for that HTML document. With this code, you are referencing the elements by their name attributes (not id). So this would provide a string containing the value for the form element with the name "email" within the form with the name "myForm".



Example:



<form name="contact-form">
Email: <input type="text" name="email" />
</form>


Executing the following JavaScript code at anytime when a value for the email field is desired would provide the value.



var contact_email = document.forms["contact-form"]["email"].value;


The contact_email variable would then contain the value entered into the input field.






share|improve this answer





























    0














    this code shows how you can use document.forms in an example with validation.


    ``



            function validation(inputs){
    if (inputs==""|| inputs=="null"){
    alert("Enter Valid Number");
    return false;
    }
    if (isNaN(inputs)){
    alert("Enter Valid Number");
    return false;
    }
    return true;
    }


    function triNum(num){
    var triangle=0;
    for(i=1 ;i <= num; i++){
    triangle += i;
    }
    return triangle;
    }

    function squareNum(num){
    var square = num * num;
    return square;
    }


    function findNums(){
    //var num = document.getElementById('number1').value;
    var num= document.forms["MagicNum"]["FirstNum"].value;
    if (validation(num)){
    document.forms["MagicNum"]["tri"].value=triNum(num);
    document.forms["MagicNum"]["square"].value=squareNum(num);
    }
    }
    </script>





    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',
      autoActivateHeartbeat: false,
      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%2f4715050%2fwhat-does-document-form-mean-in-javascript%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









      23














      document.forms["myForm"]["email"].value



      that will get the value of the "email" element within the "myForm" <form>



      <form id="myForm" name="myForm">
      <input id="email" name="email" value="some@email.com" />
      </form>


      so x will equal "some@email.com"





      document.forms will return a collection of all of the forms within a particular page. writing document.forms["myForm"] will return the form with the name "myForm" from that collection






      share|improve this answer



















      • 2




        you had explain the .value property, how about the document.form? Thanks!
        – dramasea
        Jan 17 '11 at 15:56
















      23














      document.forms["myForm"]["email"].value



      that will get the value of the "email" element within the "myForm" <form>



      <form id="myForm" name="myForm">
      <input id="email" name="email" value="some@email.com" />
      </form>


      so x will equal "some@email.com"





      document.forms will return a collection of all of the forms within a particular page. writing document.forms["myForm"] will return the form with the name "myForm" from that collection






      share|improve this answer



















      • 2




        you had explain the .value property, how about the document.form? Thanks!
        – dramasea
        Jan 17 '11 at 15:56














      23












      23








      23






      document.forms["myForm"]["email"].value



      that will get the value of the "email" element within the "myForm" <form>



      <form id="myForm" name="myForm">
      <input id="email" name="email" value="some@email.com" />
      </form>


      so x will equal "some@email.com"





      document.forms will return a collection of all of the forms within a particular page. writing document.forms["myForm"] will return the form with the name "myForm" from that collection






      share|improve this answer














      document.forms["myForm"]["email"].value



      that will get the value of the "email" element within the "myForm" <form>



      <form id="myForm" name="myForm">
      <input id="email" name="email" value="some@email.com" />
      </form>


      so x will equal "some@email.com"





      document.forms will return a collection of all of the forms within a particular page. writing document.forms["myForm"] will return the form with the name "myForm" from that collection







      share|improve this answer














      share|improve this answer



      share|improve this answer








      edited Nov 16 '18 at 14:10

























      answered Jan 17 '11 at 15:50









      hunter

      51.8k11101105




      51.8k11101105








      • 2




        you had explain the .value property, how about the document.form? Thanks!
        – dramasea
        Jan 17 '11 at 15:56














      • 2




        you had explain the .value property, how about the document.form? Thanks!
        – dramasea
        Jan 17 '11 at 15:56








      2




      2




      you had explain the .value property, how about the document.form? Thanks!
      – dramasea
      Jan 17 '11 at 15:56




      you had explain the .value property, how about the document.form? Thanks!
      – dramasea
      Jan 17 '11 at 15:56













      13














      documents.forms is an object containing all of the forms for that HTML document. With this code, you are referencing the elements by their name attributes (not id). So this would provide a string containing the value for the form element with the name "email" within the form with the name "myForm".



      Example:



      <form name="contact-form">
      Email: <input type="text" name="email" />
      </form>


      Executing the following JavaScript code at anytime when a value for the email field is desired would provide the value.



      var contact_email = document.forms["contact-form"]["email"].value;


      The contact_email variable would then contain the value entered into the input field.






      share|improve this answer


























        13














        documents.forms is an object containing all of the forms for that HTML document. With this code, you are referencing the elements by their name attributes (not id). So this would provide a string containing the value for the form element with the name "email" within the form with the name "myForm".



        Example:



        <form name="contact-form">
        Email: <input type="text" name="email" />
        </form>


        Executing the following JavaScript code at anytime when a value for the email field is desired would provide the value.



        var contact_email = document.forms["contact-form"]["email"].value;


        The contact_email variable would then contain the value entered into the input field.






        share|improve this answer
























          13












          13








          13






          documents.forms is an object containing all of the forms for that HTML document. With this code, you are referencing the elements by their name attributes (not id). So this would provide a string containing the value for the form element with the name "email" within the form with the name "myForm".



          Example:



          <form name="contact-form">
          Email: <input type="text" name="email" />
          </form>


          Executing the following JavaScript code at anytime when a value for the email field is desired would provide the value.



          var contact_email = document.forms["contact-form"]["email"].value;


          The contact_email variable would then contain the value entered into the input field.






          share|improve this answer












          documents.forms is an object containing all of the forms for that HTML document. With this code, you are referencing the elements by their name attributes (not id). So this would provide a string containing the value for the form element with the name "email" within the form with the name "myForm".



          Example:



          <form name="contact-form">
          Email: <input type="text" name="email" />
          </form>


          Executing the following JavaScript code at anytime when a value for the email field is desired would provide the value.



          var contact_email = document.forms["contact-form"]["email"].value;


          The contact_email variable would then contain the value entered into the input field.







          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Jan 17 '11 at 15:54









          Kyle

          2,20511422




          2,20511422























              0














              this code shows how you can use document.forms in an example with validation.


              ``



                      function validation(inputs){
              if (inputs==""|| inputs=="null"){
              alert("Enter Valid Number");
              return false;
              }
              if (isNaN(inputs)){
              alert("Enter Valid Number");
              return false;
              }
              return true;
              }


              function triNum(num){
              var triangle=0;
              for(i=1 ;i <= num; i++){
              triangle += i;
              }
              return triangle;
              }

              function squareNum(num){
              var square = num * num;
              return square;
              }


              function findNums(){
              //var num = document.getElementById('number1').value;
              var num= document.forms["MagicNum"]["FirstNum"].value;
              if (validation(num)){
              document.forms["MagicNum"]["tri"].value=triNum(num);
              document.forms["MagicNum"]["square"].value=squareNum(num);
              }
              }
              </script>





              share|improve this answer


























                0














                this code shows how you can use document.forms in an example with validation.


                ``



                        function validation(inputs){
                if (inputs==""|| inputs=="null"){
                alert("Enter Valid Number");
                return false;
                }
                if (isNaN(inputs)){
                alert("Enter Valid Number");
                return false;
                }
                return true;
                }


                function triNum(num){
                var triangle=0;
                for(i=1 ;i <= num; i++){
                triangle += i;
                }
                return triangle;
                }

                function squareNum(num){
                var square = num * num;
                return square;
                }


                function findNums(){
                //var num = document.getElementById('number1').value;
                var num= document.forms["MagicNum"]["FirstNum"].value;
                if (validation(num)){
                document.forms["MagicNum"]["tri"].value=triNum(num);
                document.forms["MagicNum"]["square"].value=squareNum(num);
                }
                }
                </script>





                share|improve this answer
























                  0












                  0








                  0






                  this code shows how you can use document.forms in an example with validation.


                  ``



                          function validation(inputs){
                  if (inputs==""|| inputs=="null"){
                  alert("Enter Valid Number");
                  return false;
                  }
                  if (isNaN(inputs)){
                  alert("Enter Valid Number");
                  return false;
                  }
                  return true;
                  }


                  function triNum(num){
                  var triangle=0;
                  for(i=1 ;i <= num; i++){
                  triangle += i;
                  }
                  return triangle;
                  }

                  function squareNum(num){
                  var square = num * num;
                  return square;
                  }


                  function findNums(){
                  //var num = document.getElementById('number1').value;
                  var num= document.forms["MagicNum"]["FirstNum"].value;
                  if (validation(num)){
                  document.forms["MagicNum"]["tri"].value=triNum(num);
                  document.forms["MagicNum"]["square"].value=squareNum(num);
                  }
                  }
                  </script>





                  share|improve this answer












                  this code shows how you can use document.forms in an example with validation.


                  ``



                          function validation(inputs){
                  if (inputs==""|| inputs=="null"){
                  alert("Enter Valid Number");
                  return false;
                  }
                  if (isNaN(inputs)){
                  alert("Enter Valid Number");
                  return false;
                  }
                  return true;
                  }


                  function triNum(num){
                  var triangle=0;
                  for(i=1 ;i <= num; i++){
                  triangle += i;
                  }
                  return triangle;
                  }

                  function squareNum(num){
                  var square = num * num;
                  return square;
                  }


                  function findNums(){
                  //var num = document.getElementById('number1').value;
                  var num= document.forms["MagicNum"]["FirstNum"].value;
                  if (validation(num)){
                  document.forms["MagicNum"]["tri"].value=triNum(num);
                  document.forms["MagicNum"]["square"].value=squareNum(num);
                  }
                  }
                  </script>






                  share|improve this answer












                  share|improve this answer



                  share|improve this answer










                  answered Oct 9 '18 at 16:50









                  indranatha madugalle

                  111




                  111






























                      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%2f4715050%2fwhat-does-document-form-mean-in-javascript%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







                      Popular posts from this blog

                      Coverage of Google Street View

                      Full-time equivalent

                      Surfing