jquery set value of input code example

Example 1: how to get a value using jquery

//for imput field given in HTML

<input type="text" id="myid" class="myclass" >
  
// Using ID to find value
  
$("#myid").val();

// Using Class to find value

$(".myclass").val();

Example 2: jquery value of input

$("#textInput").val() // To get value of element textInput

Example 3: jquery change value of input

$('selector').val('new value');

Example 4: jquery set input value

$("button").click(function(){
  $("input:text").val("Glenn Quagmire");
 })

Example 5: assign input text value jquery

<?= $this->Form->input('number_six', array(
     'label' => false,
     'class' => 'form-control number_six',
     'maxlength' => "1" ,
     'oninput' => "this.value=this.value.replace(/[^0-9]/g,'');"
   ));?>

$(".number_six").val("");

Example 6: set input value jquery

$("button").click(function(){
  $("input:text").val("Glenn Quagmire");
});