Get or Set values of input types using .val() method

.val()


Description: Get the value for the first input type element specified or you can set one or more values for all matched elements.


Example:

<!doctype html>
    <html lang="en">
    <head>
      <meta charset="utf-8">
      <title>val demo</title>
      <script src="http://code.bitsycode.com/bitsycode-latest.min.js"></script>
    </head>
    <body>
      
      <b>Input element value set</b><br />
      <input type="text" name="inputField" class="inputField" value="" /><br /><br />
      
      <b>Retrieved input value</b><br />
      <div class="result"></div>
      
      <script>
         
         bitsyCode.ready(function(){
            bitsyCode(".inputField").val("This was added from BitsyCode"); //SET VALUE
            
            var result = bitsyCode(".inputField").val(); //RETRIEVE VALUE
            bitsyCode(".result").text(result);
         })
         
      </script>
     
    </body>
    </html>

Preview:

Input element value set


Retrieved input value
This was added from BitsyCode
  • Usage

    • How to use:

      Using .val() will quickly allow you to get or set values of input element(s). This method has been created for it's purpose with no additional options or callbacks for efficiency.

    • SET:

      bitsyCode("element").val("content");
    • GET:

      bitsyCode("element").val();
  • Options

    • What options are there:

      There are no options for this method.

  • Returns

    • The GET returns the input elements value.
Share