1

I want the function 'name' to be activated and press the submit, while the input text changes.

How can i do it?

<form id="a"> 
  <input type="text" id="client_area" name="client_area" id="email" maxlength="5" size="5" onchange="name();">
  <input id="submit2" name="submit2" type="submit" class="btn btn-primary" value="Start"/>
</form>

<script>
  function name(){
    $("#submit2").click()
  });
);
</script>

*Also, can i add keyup too?

onchange="name();" onkeyup="name();"

Will it work?

rrk
  • 15,677
  • 4
  • 29
  • 45
macks
  • 33
  • 2
  • Possible duplicate of [Detecting input change in jQuery?](https://stackoverflow.com/questions/6458840/detecting-input-change-in-jquery) – Rohit Batra Mar 28 '18 at 11:35

3 Answers3

2

name is a reserved keyword to get the name of the function so you will get an error with name is not a function so you need to change the name of your function with Name or some other name:

function Name(){
  $("#submit2").click();
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<form id="a"> 
<input type="text" id="client_area" name="client_area" id="email" maxlength="5" size="5" onkeyup="Name()">
<input id="submit2" name="submit2" type="submit" class="btn btn-primary" value="Start"/>
</form>

This is how name is reserved as:

var fn = function(){
  //some code
};

console.log(fn.name);
Ankit Agarwal
  • 30,378
  • 5
  • 37
  • 62
0

You can do:

$('#client_area').on('keyup change', function (e) {
    $("#submit2").click();
});
Leonardo Henriques
  • 784
  • 1
  • 7
  • 22
0

Don't use onchange, id is enough;

<form id="a"> 
  <input type="text" id="client_area" name="client_area" id="email" maxlength="5" size="5" >
  <input id="submit2" name="submit2" type="submit" class="btn btn-primary" value="Start"/>
</form>

Use bind with jquery:

$('#client_area').bind('input', function() { 
    console.log("Submitted");
    $("#submit2").click();
});