onsubmit in jsfiddle not working

686 views Asked by At

I am trying to use onsubmit to call a function in javascript but it is not working. I have tried looking similar questions but nothing worked. I have also tried onclick with the submit button, that too doesn't seem to work.

<form method="POST" onsubmit="return add();" name='contact'>

I want this to work with pure JS, not jquery.

Here is the fiddle.

1

There are 1 answers

2
Arun P Johny On BEST ANSWER

By default fiddler adds the script in a onload handler as given below, so all the functions/variables created in the script will be inside the scope of the onload handler. When you use the inline event handler the script will look for the method in the global scope where the method won't be found

window.onload = function(){
    //our script here
}

so in the left panel under Frameworks & Extensions in second select box select No Wrap - In body or No Wrap - In Head