user5970644
user5970644

Reputation:

How to use more than one function in one event?

I tried to use oninput event twice but it gives me an error as you can see following.

https://prnt.sc/i6fsr0

<input id="Input1" type="text" oninput="myFunction()" oninput="this.value = this.value.replace(/[^0-9.]/g, '').replace(/(\..*)\./g, '$1');"/>

So how to use more than one function in one event?

Upvotes: 1

Views: 51

Answers (2)

guest271314
guest271314

Reputation: 1

You can include the code at the second oninput event attribute following the call to myFunction() at the first input event attribute

<script>
function myFunction() {console.log("myFunction")}
</script>
<input id="Input1" type="text" oninput="myFunction(); this.value = this.value.replace(/[^0-9.]/g, '').replace(/(\..*)\./g, '$1')"/>

Upvotes: 0

Sajeetharan
Sajeetharan

Reputation: 222720

Place the logic inside the function itself

myFunction(){
  //whatever existing logic
  this.value = this.value.replace(/[^0-9.]/g, '').replace(/(\..*)\./g, '$1');
}

or create another function for the logic and use ;

<input id="Input1" type="text" oninput="myFunction();mysecondFunction()"/>

Upvotes: 1

Related Questions