JavaScript HTML-form submit button not running the OnSubmit script associated with it html form submit button,html form submit javascript,html form

I'm making a chrome extension, and so far I'm just testing some things. The HTML for the extension is this:

<!doctype html>
<html>
  <head>
    <title>Title</title>
    <script src="processform.js"></script>
  </head>
  <body>
    <form name="myform" onSubmit="ExampleJS()">
         First name: <input type="text" id="fname" name="firstname" /><br />
         Last name:  <input type="text" id="lname" name="lastname" /><br />
        <input name="Submit"  type="submit" value="Update" />
    </form>
  </body>
</html>

The processform.js file is this:

function ExampleJS(){
    var jFirst = document.getElementById("fname").value;
    var jLast = document.getElementById("lname").value;
    alert("Your name is: " + jFirst + " " + jLast);
}

When I press the submit button the alert doesn't appear.

Answer:1

You cannot use inline code in a Chrome extension due to its Content Security Policy, and setting onsubmit in the element counts as inline.

A jQuery-based solution (you will need to include jQuery with the extension and add it to the page, but there's no harm in that):

// processform.js
$(document).ready(function(){
  // Bind from JS, not inline
  $("form").submit(ExampleJS);
});

A pure JavaScript solution would be:

// processform.js
document.addEventListener('DOMContentLoaded', function(){
  // Bind from JS, not inline
  document.forms["myform"].addEventListener('submit', ExampleJS);
});
Answer:2

I have been having some trouble in creating a simple notification box. Basically the objective here when I click the submit button input type=button it will display a simple notification box like this....

I have been having some trouble in creating a simple notification box. Basically the objective here when I click the submit button input type=button it will display a simple notification box like this....

I was reading the javascipt code in some application and code was this getTotalFees:function(){ return this.grid &&this.grid.getStore().sum('fees'); } Now i am confused what ...

I was reading the javascipt code in some application and code was this getTotalFees:function(){ return this.grid &&this.grid.getStore().sum('fees'); } Now i am confused what ...

  1. what does return do in python
  2. what does return service requested mean
  3. what does return on equity mean
  4. what does return mean
  5. what does return on assets mean
  6. what does return to sender mean
  7. what does return do in java
  8. what does return of the mack mean
  9. what does return on investment mean
  10. what does return accepted mean
  11. what does return on assets measure
  12. what does return do in javascript
  13. what does return status printed mean
  14. what does return on sales mean
  15. what does return 0 do in c++
  16. what does return of service mean
  17. what does return mean in java
  18. what does return do in c++
  19. what does return to sender processed mean
  20. what does return in transit mean

I'll start off with mentioning I'm very new to Angular so I'm probably not doing things in the correct "Angular way". I have the following ng-repeat looping through some data - the correct data is ...

I'll start off with mentioning I'm very new to Angular so I'm probably not doing things in the correct "Angular way". I have the following ng-repeat looping through some data - the correct data is ...

Having a div element, I can style its bg-color through either Javascript or CSS. Is there any difference between the two, or which one should we use? div:hover {background-color:gray;} or $( div)....

Having a div element, I can style its bg-color through either Javascript or CSS. Is there any difference between the two, or which one should we use? div:hover {background-color:gray;} or $( div)....

  1. hover through the fog and filthy air
  2. hover through div
  3. hover through js
  4. hover through element
  5. hover through css
  6. hover through the fog
  7. hover through meaning
  8. hover through the filthy air
  9. hover through javascript
  10. hover through jquery
  11. css hover through element
  12. mouse hover through javascriptexecutor
  13. mouse hover through javascript
  14. html hover through element
  15. macbeth hover through the fog
  16. javascript hover through element
  17. add hover through jquery
  18. hover effect through css
  19. hover effect through javascript
  20. css hover through javascript