javascript - How to add onChange function for all HTML form fields -


My HTML page has 10 text fields.

There are currently no on-change events available for all ten areas.

  & lt; Input type = "text" name = "text1" value = "1" & gt; & Lt; Input type = "text" name = "text2" value = "2" & gt; & Lt; Input type = "text" name = "text3" value = "3" & gt; & Lt; Input type = "text" name = "text4" value = "" & gt; & Lt; Input type = "text" name = "text5" value = "" & gt; & Lt; Input type = "text" name = "text6" value = "" & gt; ...   

Now, I want to add change function to all the fields, type the field input .

How do I add Change or Change in my JS section?

In the on-change function, I will call the AJAX function which will be valid if the Field Hacking Keywords

then my question is:

How to add change function to My field should be dynamically lower:

  & lt; Input type = "text" name = "text1" value = "1" onChange = "javascript: fnName" onBlur = "javascript: fnName" & gt; & Lt; Input type = "text" name = "text2" value = "2" onChange = "javascript: fnName" onBlur = "javascript: fnName" & gt; & Lt; Input type = "text" name = "text3" value = "3" onChange = "javascript: fnName" onBlur = "javascript: fnName" & gt; & Lt; Input type = "text" name = "text4" value = "" change = "javascript: fnName" onBlur = "javascript: fnName" & gt; & Lt; Input type = "text" name = "text5" value = "" onChange = "javascript: fnName" onBlur = "javascript: fnName" & gt; & Lt; Input type = "text" name = "text6" value = "" change = "javascript: fnName" onBlur = "javascript: fnName" & gt; & Lt; Input type = "text" name = "text7" value = "" onChange = "javascript: fnName" onBlur = "javascript: fnName" & gt;  

It shows that vanilla can be obtained with JavaScript.

Here is a simple loop to imitate a HTML5 placeholder. & Lt; & Lt; & Gt; & Gt;

  soon = 'type something here'; Var textFields = document.querySelectorAll ('input [name =' 'text'] '); Var Index = 0; (Index = 0; index & lt; textFields.length; ++ index) for {var textField = textFields [index]; TextField.addEventListener ('Change', On ChangeHandler); TextField.addEventListener ('Focus', onFocusHandler); TextField.addEventListener ('Blur', onblur handler); TextField.value = sign; Console.log (field); } Function On Change Handler () {// Something ...} Focus Sandler () on the function {if (this.value === Prompt) {this.value = ''; }} Function BlurHandler () {if (this.value === '') {this.value = prompt; }}    

Comments

Popular posts from this blog

ios - Adding an SKSpriteNode to SKScene from a child SKSpriteNode -

Matlab transpose a table vector -

c# - Textbox not clickable but editable -