form onsubmit=“return function()” but form still submitting and page reloading
up vote
0
down vote
favorite
I want a form to not submit and reload the page. Instead I want it to run the runTest()
function.
I've tried the following:
<form id="dataForm" onsubmit="return runTest()">
<input type="text" id="text" placeholder="enter some text" required maxlength="10" pattern="^[a-z,A-Z]{1,10}$"><br />
<input type="text" id="number" placeholder="enter a number" required maxlength="10" pattern="d{10}"><br />
<input type="submit" id="submitTest">
</form>
<script src="../test/test2.js"></script>
and in ../test/test2.js:
function runTest() {...}
However, the form submits and the page reloads, and runTest()
does not run.
Help appreciated.
From this answer, I've altered my runTest()
function to be:
function runTest() {
var validate = true;
describe("Simple assert", function() {
it("foo != bar", function() {
assert('foo' != 'bar', 'foo is not bar');
});
it('should return true if field is valid', function(){
var isValidText = isValidField('text');
var isValidNumber = isValidField('number');
assert.equal(isValidText, true);
assert.equal(isValidNumber, true);
});
validate = false;
});
return validate;
}
runTest()
has been browserfyd into test2.js
However, the form still submits, the page reloads, and runTest()
does not run.
javascript forms
add a comment |
up vote
0
down vote
favorite
I want a form to not submit and reload the page. Instead I want it to run the runTest()
function.
I've tried the following:
<form id="dataForm" onsubmit="return runTest()">
<input type="text" id="text" placeholder="enter some text" required maxlength="10" pattern="^[a-z,A-Z]{1,10}$"><br />
<input type="text" id="number" placeholder="enter a number" required maxlength="10" pattern="d{10}"><br />
<input type="submit" id="submitTest">
</form>
<script src="../test/test2.js"></script>
and in ../test/test2.js:
function runTest() {...}
However, the form submits and the page reloads, and runTest()
does not run.
Help appreciated.
From this answer, I've altered my runTest()
function to be:
function runTest() {
var validate = true;
describe("Simple assert", function() {
it("foo != bar", function() {
assert('foo' != 'bar', 'foo is not bar');
});
it('should return true if field is valid', function(){
var isValidText = isValidField('text');
var isValidNumber = isValidField('number');
assert.equal(isValidText, true);
assert.equal(isValidNumber, true);
});
validate = false;
});
return validate;
}
runTest()
has been browserfyd into test2.js
However, the form still submits, the page reloads, and runTest()
does not run.
javascript forms
add a comment |
up vote
0
down vote
favorite
up vote
0
down vote
favorite
I want a form to not submit and reload the page. Instead I want it to run the runTest()
function.
I've tried the following:
<form id="dataForm" onsubmit="return runTest()">
<input type="text" id="text" placeholder="enter some text" required maxlength="10" pattern="^[a-z,A-Z]{1,10}$"><br />
<input type="text" id="number" placeholder="enter a number" required maxlength="10" pattern="d{10}"><br />
<input type="submit" id="submitTest">
</form>
<script src="../test/test2.js"></script>
and in ../test/test2.js:
function runTest() {...}
However, the form submits and the page reloads, and runTest()
does not run.
Help appreciated.
From this answer, I've altered my runTest()
function to be:
function runTest() {
var validate = true;
describe("Simple assert", function() {
it("foo != bar", function() {
assert('foo' != 'bar', 'foo is not bar');
});
it('should return true if field is valid', function(){
var isValidText = isValidField('text');
var isValidNumber = isValidField('number');
assert.equal(isValidText, true);
assert.equal(isValidNumber, true);
});
validate = false;
});
return validate;
}
runTest()
has been browserfyd into test2.js
However, the form still submits, the page reloads, and runTest()
does not run.
javascript forms
I want a form to not submit and reload the page. Instead I want it to run the runTest()
function.
I've tried the following:
<form id="dataForm" onsubmit="return runTest()">
<input type="text" id="text" placeholder="enter some text" required maxlength="10" pattern="^[a-z,A-Z]{1,10}$"><br />
<input type="text" id="number" placeholder="enter a number" required maxlength="10" pattern="d{10}"><br />
<input type="submit" id="submitTest">
</form>
<script src="../test/test2.js"></script>
and in ../test/test2.js:
function runTest() {...}
However, the form submits and the page reloads, and runTest()
does not run.
Help appreciated.
From this answer, I've altered my runTest()
function to be:
function runTest() {
var validate = true;
describe("Simple assert", function() {
it("foo != bar", function() {
assert('foo' != 'bar', 'foo is not bar');
});
it('should return true if field is valid', function(){
var isValidText = isValidField('text');
var isValidNumber = isValidField('number');
assert.equal(isValidText, true);
assert.equal(isValidNumber, true);
});
validate = false;
});
return validate;
}
runTest()
has been browserfyd into test2.js
However, the form still submits, the page reloads, and runTest()
does not run.
javascript forms
javascript forms
asked Nov 20 at 6:58
Steve
45942862
45942862
add a comment |
add a comment |
4 Answers
4
active
oldest
votes
up vote
0
down vote
accepted
You can handle the submit event of the form programmatically with Javascript using the addEventListener
function as below:
document.getElementById("dataForm").addEventListener("submit", function(e){
e.preventDefault() //to block page reload
var validate = true;
describe("Simple assert", function() {
it("foo != bar", function() {
assert('foo' != 'bar', 'foo is not bar');
});
it('should return true if field is valid', function(){
var isValidText = isValidField('text');
var isValidNumber = isValidField('number');
assert.equal(isValidText, true);
assert.equal(isValidNumber, true);
});
validate = false;
});
return validate;
})
<form id="dataForm">
<input type="text" id="text" placeholder="enter some text" required maxlength="10" pattern="^[a-z,A-Z]{1,10}$"><br />
<input type="text" id="number" placeholder="enter a number" required maxlength="10" pattern="d{10}"><br />
<input type="submit" id="submitTest">
</form>
I can't bringrunTest()
into the.html
file because it is typescript in an external file that has been browserfy-d into a javascript file.
– Steve
Nov 20 at 7:30
i never asked you to put the script in your.html
;).... Normally it should work in your browseryfied file
– Steve Nosse
Nov 20 at 7:42
OK. So does thedocument.getElementById("dataForm").addEventListener("submit", function(e)
go insiderunTest
? Because the rest of the code in your answer is. :)
– Steve
Nov 20 at 7:48
No.. Instead on callingrunTest
when the form is submitted, i handle the submit event with javascript; so i replaced therunTest
declaration bydocument.getElementById(...
... I think it's more professional like that
– Steve Nosse
Nov 20 at 8:00
Okay. We're getting somewhere. The form does not submit and the page does not reload now. I'll need to work out why the asserts are not running now. Thanks for your help.
– Steve
Nov 20 at 8:04
|
show 2 more comments
up vote
2
down vote
pass event in your html.
onsubmit="return runTest(event)"
and then call preventDefault in your function and return false at the end.
function runTest(e) {
e.preventDefault();
.
.
.
return false;
}
Thanks. Tried that and the form still submits / page reloads.
– Steve
Nov 20 at 7:19
@Steve alsoreturn false
at the end of function.
– Hadi290
Nov 20 at 7:24
Tried that too, same thing happens. :)
– Steve
Nov 20 at 7:25
add a comment |
up vote
1
down vote
Change the type of that button to button
instead submit
then submit your form using JavaScript like this
document.getElementById("dataForm").submit();
and remove the return part from you onclick attribute.
I tried that. I end up with this code, but the browser gets trapped in a loop.
– Steve
Nov 20 at 7:37
You are directly including this statement document.getElementById("dataForm").submit(); inside script element so when the page load your form automatically get submitted .
– RopAli Munshi
Nov 20 at 7:44
I see. So where do I put your code please?
– Steve
Nov 20 at 7:46
Right question would when to call that method and the simple answer is that when you want to submit the form if you want to submit your form after the runTest function completes then you should call that submit method at the end of runTest function.
– RopAli Munshi
Nov 20 at 7:50
OK. I see this in my code editor when I place it at the end ofrunTest
.
– Steve
Nov 20 at 7:56
add a comment |
up vote
0
down vote
Please try the below code,
use e.preventDefault();
dont send the response as a veriable
use return false;
instead of return validate;
function runTest() {
e.preventDefault();
describe("Simple assert", function() {
it("foo != bar", function() {
assert('foo' != 'bar', 'foo is not bar');
});
it('should return true if field is valid', function(){
var isValidText = isValidField('text');
var isValidNumber = isValidField('number');
assert.equal(isValidText, true);
assert.equal(isValidNumber, true);
});
return false;
});
}
or
function runTest() {
var validate = 'true';
describe("Simple assert", function() {
it("foo != bar", function() {
assert('foo' != 'bar', 'foo is not bar');
});
it('should return true if field is valid', function(){
var isValidText = isValidField('text');
var isValidNumber = isValidField('number');
assert.equal(isValidText, true);
assert.equal(isValidNumber, true);
});
validate = 'false';
});
alert(validate)
if(validate=='false'){
return false;
}
}
That didn't work unfortunately.
– Steve
Nov 20 at 7:28
please try my second ans, I add a code to alert the value of the variable validate. so you can easy to check
– JIJOMON K.A
Nov 20 at 7:29
Tried the second code, and no alert occurred?
– Steve
Nov 20 at 7:34
@Steve : Then there is an error in the above codes. please add an alert() in function top. and also check your script path is correct
– JIJOMON K.A
Nov 20 at 7:35
I've added an alert just inside runTest() and it doesn't fire. I have the path correct I believe.
– Steve
Nov 20 at 7:40
add a comment |
4 Answers
4
active
oldest
votes
4 Answers
4
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
0
down vote
accepted
You can handle the submit event of the form programmatically with Javascript using the addEventListener
function as below:
document.getElementById("dataForm").addEventListener("submit", function(e){
e.preventDefault() //to block page reload
var validate = true;
describe("Simple assert", function() {
it("foo != bar", function() {
assert('foo' != 'bar', 'foo is not bar');
});
it('should return true if field is valid', function(){
var isValidText = isValidField('text');
var isValidNumber = isValidField('number');
assert.equal(isValidText, true);
assert.equal(isValidNumber, true);
});
validate = false;
});
return validate;
})
<form id="dataForm">
<input type="text" id="text" placeholder="enter some text" required maxlength="10" pattern="^[a-z,A-Z]{1,10}$"><br />
<input type="text" id="number" placeholder="enter a number" required maxlength="10" pattern="d{10}"><br />
<input type="submit" id="submitTest">
</form>
I can't bringrunTest()
into the.html
file because it is typescript in an external file that has been browserfy-d into a javascript file.
– Steve
Nov 20 at 7:30
i never asked you to put the script in your.html
;).... Normally it should work in your browseryfied file
– Steve Nosse
Nov 20 at 7:42
OK. So does thedocument.getElementById("dataForm").addEventListener("submit", function(e)
go insiderunTest
? Because the rest of the code in your answer is. :)
– Steve
Nov 20 at 7:48
No.. Instead on callingrunTest
when the form is submitted, i handle the submit event with javascript; so i replaced therunTest
declaration bydocument.getElementById(...
... I think it's more professional like that
– Steve Nosse
Nov 20 at 8:00
Okay. We're getting somewhere. The form does not submit and the page does not reload now. I'll need to work out why the asserts are not running now. Thanks for your help.
– Steve
Nov 20 at 8:04
|
show 2 more comments
up vote
0
down vote
accepted
You can handle the submit event of the form programmatically with Javascript using the addEventListener
function as below:
document.getElementById("dataForm").addEventListener("submit", function(e){
e.preventDefault() //to block page reload
var validate = true;
describe("Simple assert", function() {
it("foo != bar", function() {
assert('foo' != 'bar', 'foo is not bar');
});
it('should return true if field is valid', function(){
var isValidText = isValidField('text');
var isValidNumber = isValidField('number');
assert.equal(isValidText, true);
assert.equal(isValidNumber, true);
});
validate = false;
});
return validate;
})
<form id="dataForm">
<input type="text" id="text" placeholder="enter some text" required maxlength="10" pattern="^[a-z,A-Z]{1,10}$"><br />
<input type="text" id="number" placeholder="enter a number" required maxlength="10" pattern="d{10}"><br />
<input type="submit" id="submitTest">
</form>
I can't bringrunTest()
into the.html
file because it is typescript in an external file that has been browserfy-d into a javascript file.
– Steve
Nov 20 at 7:30
i never asked you to put the script in your.html
;).... Normally it should work in your browseryfied file
– Steve Nosse
Nov 20 at 7:42
OK. So does thedocument.getElementById("dataForm").addEventListener("submit", function(e)
go insiderunTest
? Because the rest of the code in your answer is. :)
– Steve
Nov 20 at 7:48
No.. Instead on callingrunTest
when the form is submitted, i handle the submit event with javascript; so i replaced therunTest
declaration bydocument.getElementById(...
... I think it's more professional like that
– Steve Nosse
Nov 20 at 8:00
Okay. We're getting somewhere. The form does not submit and the page does not reload now. I'll need to work out why the asserts are not running now. Thanks for your help.
– Steve
Nov 20 at 8:04
|
show 2 more comments
up vote
0
down vote
accepted
up vote
0
down vote
accepted
You can handle the submit event of the form programmatically with Javascript using the addEventListener
function as below:
document.getElementById("dataForm").addEventListener("submit", function(e){
e.preventDefault() //to block page reload
var validate = true;
describe("Simple assert", function() {
it("foo != bar", function() {
assert('foo' != 'bar', 'foo is not bar');
});
it('should return true if field is valid', function(){
var isValidText = isValidField('text');
var isValidNumber = isValidField('number');
assert.equal(isValidText, true);
assert.equal(isValidNumber, true);
});
validate = false;
});
return validate;
})
<form id="dataForm">
<input type="text" id="text" placeholder="enter some text" required maxlength="10" pattern="^[a-z,A-Z]{1,10}$"><br />
<input type="text" id="number" placeholder="enter a number" required maxlength="10" pattern="d{10}"><br />
<input type="submit" id="submitTest">
</form>
You can handle the submit event of the form programmatically with Javascript using the addEventListener
function as below:
document.getElementById("dataForm").addEventListener("submit", function(e){
e.preventDefault() //to block page reload
var validate = true;
describe("Simple assert", function() {
it("foo != bar", function() {
assert('foo' != 'bar', 'foo is not bar');
});
it('should return true if field is valid', function(){
var isValidText = isValidField('text');
var isValidNumber = isValidField('number');
assert.equal(isValidText, true);
assert.equal(isValidNumber, true);
});
validate = false;
});
return validate;
})
<form id="dataForm">
<input type="text" id="text" placeholder="enter some text" required maxlength="10" pattern="^[a-z,A-Z]{1,10}$"><br />
<input type="text" id="number" placeholder="enter a number" required maxlength="10" pattern="d{10}"><br />
<input type="submit" id="submitTest">
</form>
document.getElementById("dataForm").addEventListener("submit", function(e){
e.preventDefault() //to block page reload
var validate = true;
describe("Simple assert", function() {
it("foo != bar", function() {
assert('foo' != 'bar', 'foo is not bar');
});
it('should return true if field is valid', function(){
var isValidText = isValidField('text');
var isValidNumber = isValidField('number');
assert.equal(isValidText, true);
assert.equal(isValidNumber, true);
});
validate = false;
});
return validate;
})
<form id="dataForm">
<input type="text" id="text" placeholder="enter some text" required maxlength="10" pattern="^[a-z,A-Z]{1,10}$"><br />
<input type="text" id="number" placeholder="enter a number" required maxlength="10" pattern="d{10}"><br />
<input type="submit" id="submitTest">
</form>
document.getElementById("dataForm").addEventListener("submit", function(e){
e.preventDefault() //to block page reload
var validate = true;
describe("Simple assert", function() {
it("foo != bar", function() {
assert('foo' != 'bar', 'foo is not bar');
});
it('should return true if field is valid', function(){
var isValidText = isValidField('text');
var isValidNumber = isValidField('number');
assert.equal(isValidText, true);
assert.equal(isValidNumber, true);
});
validate = false;
});
return validate;
})
<form id="dataForm">
<input type="text" id="text" placeholder="enter some text" required maxlength="10" pattern="^[a-z,A-Z]{1,10}$"><br />
<input type="text" id="number" placeholder="enter a number" required maxlength="10" pattern="d{10}"><br />
<input type="submit" id="submitTest">
</form>
answered Nov 20 at 7:28
Steve Nosse
217111
217111
I can't bringrunTest()
into the.html
file because it is typescript in an external file that has been browserfy-d into a javascript file.
– Steve
Nov 20 at 7:30
i never asked you to put the script in your.html
;).... Normally it should work in your browseryfied file
– Steve Nosse
Nov 20 at 7:42
OK. So does thedocument.getElementById("dataForm").addEventListener("submit", function(e)
go insiderunTest
? Because the rest of the code in your answer is. :)
– Steve
Nov 20 at 7:48
No.. Instead on callingrunTest
when the form is submitted, i handle the submit event with javascript; so i replaced therunTest
declaration bydocument.getElementById(...
... I think it's more professional like that
– Steve Nosse
Nov 20 at 8:00
Okay. We're getting somewhere. The form does not submit and the page does not reload now. I'll need to work out why the asserts are not running now. Thanks for your help.
– Steve
Nov 20 at 8:04
|
show 2 more comments
I can't bringrunTest()
into the.html
file because it is typescript in an external file that has been browserfy-d into a javascript file.
– Steve
Nov 20 at 7:30
i never asked you to put the script in your.html
;).... Normally it should work in your browseryfied file
– Steve Nosse
Nov 20 at 7:42
OK. So does thedocument.getElementById("dataForm").addEventListener("submit", function(e)
go insiderunTest
? Because the rest of the code in your answer is. :)
– Steve
Nov 20 at 7:48
No.. Instead on callingrunTest
when the form is submitted, i handle the submit event with javascript; so i replaced therunTest
declaration bydocument.getElementById(...
... I think it's more professional like that
– Steve Nosse
Nov 20 at 8:00
Okay. We're getting somewhere. The form does not submit and the page does not reload now. I'll need to work out why the asserts are not running now. Thanks for your help.
– Steve
Nov 20 at 8:04
I can't bring
runTest()
into the .html
file because it is typescript in an external file that has been browserfy-d into a javascript file.– Steve
Nov 20 at 7:30
I can't bring
runTest()
into the .html
file because it is typescript in an external file that has been browserfy-d into a javascript file.– Steve
Nov 20 at 7:30
i never asked you to put the script in your
.html
;).... Normally it should work in your browseryfied file– Steve Nosse
Nov 20 at 7:42
i never asked you to put the script in your
.html
;).... Normally it should work in your browseryfied file– Steve Nosse
Nov 20 at 7:42
OK. So does the
document.getElementById("dataForm").addEventListener("submit", function(e)
go inside runTest
? Because the rest of the code in your answer is. :)– Steve
Nov 20 at 7:48
OK. So does the
document.getElementById("dataForm").addEventListener("submit", function(e)
go inside runTest
? Because the rest of the code in your answer is. :)– Steve
Nov 20 at 7:48
No.. Instead on calling
runTest
when the form is submitted, i handle the submit event with javascript; so i replaced the runTest
declaration by document.getElementById(...
... I think it's more professional like that– Steve Nosse
Nov 20 at 8:00
No.. Instead on calling
runTest
when the form is submitted, i handle the submit event with javascript; so i replaced the runTest
declaration by document.getElementById(...
... I think it's more professional like that– Steve Nosse
Nov 20 at 8:00
Okay. We're getting somewhere. The form does not submit and the page does not reload now. I'll need to work out why the asserts are not running now. Thanks for your help.
– Steve
Nov 20 at 8:04
Okay. We're getting somewhere. The form does not submit and the page does not reload now. I'll need to work out why the asserts are not running now. Thanks for your help.
– Steve
Nov 20 at 8:04
|
show 2 more comments
up vote
2
down vote
pass event in your html.
onsubmit="return runTest(event)"
and then call preventDefault in your function and return false at the end.
function runTest(e) {
e.preventDefault();
.
.
.
return false;
}
Thanks. Tried that and the form still submits / page reloads.
– Steve
Nov 20 at 7:19
@Steve alsoreturn false
at the end of function.
– Hadi290
Nov 20 at 7:24
Tried that too, same thing happens. :)
– Steve
Nov 20 at 7:25
add a comment |
up vote
2
down vote
pass event in your html.
onsubmit="return runTest(event)"
and then call preventDefault in your function and return false at the end.
function runTest(e) {
e.preventDefault();
.
.
.
return false;
}
Thanks. Tried that and the form still submits / page reloads.
– Steve
Nov 20 at 7:19
@Steve alsoreturn false
at the end of function.
– Hadi290
Nov 20 at 7:24
Tried that too, same thing happens. :)
– Steve
Nov 20 at 7:25
add a comment |
up vote
2
down vote
up vote
2
down vote
pass event in your html.
onsubmit="return runTest(event)"
and then call preventDefault in your function and return false at the end.
function runTest(e) {
e.preventDefault();
.
.
.
return false;
}
pass event in your html.
onsubmit="return runTest(event)"
and then call preventDefault in your function and return false at the end.
function runTest(e) {
e.preventDefault();
.
.
.
return false;
}
edited Nov 20 at 7:26
answered Nov 20 at 7:16
Hadi290
188214
188214
Thanks. Tried that and the form still submits / page reloads.
– Steve
Nov 20 at 7:19
@Steve alsoreturn false
at the end of function.
– Hadi290
Nov 20 at 7:24
Tried that too, same thing happens. :)
– Steve
Nov 20 at 7:25
add a comment |
Thanks. Tried that and the form still submits / page reloads.
– Steve
Nov 20 at 7:19
@Steve alsoreturn false
at the end of function.
– Hadi290
Nov 20 at 7:24
Tried that too, same thing happens. :)
– Steve
Nov 20 at 7:25
Thanks. Tried that and the form still submits / page reloads.
– Steve
Nov 20 at 7:19
Thanks. Tried that and the form still submits / page reloads.
– Steve
Nov 20 at 7:19
@Steve also
return false
at the end of function.– Hadi290
Nov 20 at 7:24
@Steve also
return false
at the end of function.– Hadi290
Nov 20 at 7:24
Tried that too, same thing happens. :)
– Steve
Nov 20 at 7:25
Tried that too, same thing happens. :)
– Steve
Nov 20 at 7:25
add a comment |
up vote
1
down vote
Change the type of that button to button
instead submit
then submit your form using JavaScript like this
document.getElementById("dataForm").submit();
and remove the return part from you onclick attribute.
I tried that. I end up with this code, but the browser gets trapped in a loop.
– Steve
Nov 20 at 7:37
You are directly including this statement document.getElementById("dataForm").submit(); inside script element so when the page load your form automatically get submitted .
– RopAli Munshi
Nov 20 at 7:44
I see. So where do I put your code please?
– Steve
Nov 20 at 7:46
Right question would when to call that method and the simple answer is that when you want to submit the form if you want to submit your form after the runTest function completes then you should call that submit method at the end of runTest function.
– RopAli Munshi
Nov 20 at 7:50
OK. I see this in my code editor when I place it at the end ofrunTest
.
– Steve
Nov 20 at 7:56
add a comment |
up vote
1
down vote
Change the type of that button to button
instead submit
then submit your form using JavaScript like this
document.getElementById("dataForm").submit();
and remove the return part from you onclick attribute.
I tried that. I end up with this code, but the browser gets trapped in a loop.
– Steve
Nov 20 at 7:37
You are directly including this statement document.getElementById("dataForm").submit(); inside script element so when the page load your form automatically get submitted .
– RopAli Munshi
Nov 20 at 7:44
I see. So where do I put your code please?
– Steve
Nov 20 at 7:46
Right question would when to call that method and the simple answer is that when you want to submit the form if you want to submit your form after the runTest function completes then you should call that submit method at the end of runTest function.
– RopAli Munshi
Nov 20 at 7:50
OK. I see this in my code editor when I place it at the end ofrunTest
.
– Steve
Nov 20 at 7:56
add a comment |
up vote
1
down vote
up vote
1
down vote
Change the type of that button to button
instead submit
then submit your form using JavaScript like this
document.getElementById("dataForm").submit();
and remove the return part from you onclick attribute.
Change the type of that button to button
instead submit
then submit your form using JavaScript like this
document.getElementById("dataForm").submit();
and remove the return part from you onclick attribute.
answered Nov 20 at 7:26
RopAli Munshi
1418
1418
I tried that. I end up with this code, but the browser gets trapped in a loop.
– Steve
Nov 20 at 7:37
You are directly including this statement document.getElementById("dataForm").submit(); inside script element so when the page load your form automatically get submitted .
– RopAli Munshi
Nov 20 at 7:44
I see. So where do I put your code please?
– Steve
Nov 20 at 7:46
Right question would when to call that method and the simple answer is that when you want to submit the form if you want to submit your form after the runTest function completes then you should call that submit method at the end of runTest function.
– RopAli Munshi
Nov 20 at 7:50
OK. I see this in my code editor when I place it at the end ofrunTest
.
– Steve
Nov 20 at 7:56
add a comment |
I tried that. I end up with this code, but the browser gets trapped in a loop.
– Steve
Nov 20 at 7:37
You are directly including this statement document.getElementById("dataForm").submit(); inside script element so when the page load your form automatically get submitted .
– RopAli Munshi
Nov 20 at 7:44
I see. So where do I put your code please?
– Steve
Nov 20 at 7:46
Right question would when to call that method and the simple answer is that when you want to submit the form if you want to submit your form after the runTest function completes then you should call that submit method at the end of runTest function.
– RopAli Munshi
Nov 20 at 7:50
OK. I see this in my code editor when I place it at the end ofrunTest
.
– Steve
Nov 20 at 7:56
I tried that. I end up with this code, but the browser gets trapped in a loop.
– Steve
Nov 20 at 7:37
I tried that. I end up with this code, but the browser gets trapped in a loop.
– Steve
Nov 20 at 7:37
You are directly including this statement document.getElementById("dataForm").submit(); inside script element so when the page load your form automatically get submitted .
– RopAli Munshi
Nov 20 at 7:44
You are directly including this statement document.getElementById("dataForm").submit(); inside script element so when the page load your form automatically get submitted .
– RopAli Munshi
Nov 20 at 7:44
I see. So where do I put your code please?
– Steve
Nov 20 at 7:46
I see. So where do I put your code please?
– Steve
Nov 20 at 7:46
Right question would when to call that method and the simple answer is that when you want to submit the form if you want to submit your form after the runTest function completes then you should call that submit method at the end of runTest function.
– RopAli Munshi
Nov 20 at 7:50
Right question would when to call that method and the simple answer is that when you want to submit the form if you want to submit your form after the runTest function completes then you should call that submit method at the end of runTest function.
– RopAli Munshi
Nov 20 at 7:50
OK. I see this in my code editor when I place it at the end of
runTest
.– Steve
Nov 20 at 7:56
OK. I see this in my code editor when I place it at the end of
runTest
.– Steve
Nov 20 at 7:56
add a comment |
up vote
0
down vote
Please try the below code,
use e.preventDefault();
dont send the response as a veriable
use return false;
instead of return validate;
function runTest() {
e.preventDefault();
describe("Simple assert", function() {
it("foo != bar", function() {
assert('foo' != 'bar', 'foo is not bar');
});
it('should return true if field is valid', function(){
var isValidText = isValidField('text');
var isValidNumber = isValidField('number');
assert.equal(isValidText, true);
assert.equal(isValidNumber, true);
});
return false;
});
}
or
function runTest() {
var validate = 'true';
describe("Simple assert", function() {
it("foo != bar", function() {
assert('foo' != 'bar', 'foo is not bar');
});
it('should return true if field is valid', function(){
var isValidText = isValidField('text');
var isValidNumber = isValidField('number');
assert.equal(isValidText, true);
assert.equal(isValidNumber, true);
});
validate = 'false';
});
alert(validate)
if(validate=='false'){
return false;
}
}
That didn't work unfortunately.
– Steve
Nov 20 at 7:28
please try my second ans, I add a code to alert the value of the variable validate. so you can easy to check
– JIJOMON K.A
Nov 20 at 7:29
Tried the second code, and no alert occurred?
– Steve
Nov 20 at 7:34
@Steve : Then there is an error in the above codes. please add an alert() in function top. and also check your script path is correct
– JIJOMON K.A
Nov 20 at 7:35
I've added an alert just inside runTest() and it doesn't fire. I have the path correct I believe.
– Steve
Nov 20 at 7:40
add a comment |
up vote
0
down vote
Please try the below code,
use e.preventDefault();
dont send the response as a veriable
use return false;
instead of return validate;
function runTest() {
e.preventDefault();
describe("Simple assert", function() {
it("foo != bar", function() {
assert('foo' != 'bar', 'foo is not bar');
});
it('should return true if field is valid', function(){
var isValidText = isValidField('text');
var isValidNumber = isValidField('number');
assert.equal(isValidText, true);
assert.equal(isValidNumber, true);
});
return false;
});
}
or
function runTest() {
var validate = 'true';
describe("Simple assert", function() {
it("foo != bar", function() {
assert('foo' != 'bar', 'foo is not bar');
});
it('should return true if field is valid', function(){
var isValidText = isValidField('text');
var isValidNumber = isValidField('number');
assert.equal(isValidText, true);
assert.equal(isValidNumber, true);
});
validate = 'false';
});
alert(validate)
if(validate=='false'){
return false;
}
}
That didn't work unfortunately.
– Steve
Nov 20 at 7:28
please try my second ans, I add a code to alert the value of the variable validate. so you can easy to check
– JIJOMON K.A
Nov 20 at 7:29
Tried the second code, and no alert occurred?
– Steve
Nov 20 at 7:34
@Steve : Then there is an error in the above codes. please add an alert() in function top. and also check your script path is correct
– JIJOMON K.A
Nov 20 at 7:35
I've added an alert just inside runTest() and it doesn't fire. I have the path correct I believe.
– Steve
Nov 20 at 7:40
add a comment |
up vote
0
down vote
up vote
0
down vote
Please try the below code,
use e.preventDefault();
dont send the response as a veriable
use return false;
instead of return validate;
function runTest() {
e.preventDefault();
describe("Simple assert", function() {
it("foo != bar", function() {
assert('foo' != 'bar', 'foo is not bar');
});
it('should return true if field is valid', function(){
var isValidText = isValidField('text');
var isValidNumber = isValidField('number');
assert.equal(isValidText, true);
assert.equal(isValidNumber, true);
});
return false;
});
}
or
function runTest() {
var validate = 'true';
describe("Simple assert", function() {
it("foo != bar", function() {
assert('foo' != 'bar', 'foo is not bar');
});
it('should return true if field is valid', function(){
var isValidText = isValidField('text');
var isValidNumber = isValidField('number');
assert.equal(isValidText, true);
assert.equal(isValidNumber, true);
});
validate = 'false';
});
alert(validate)
if(validate=='false'){
return false;
}
}
Please try the below code,
use e.preventDefault();
dont send the response as a veriable
use return false;
instead of return validate;
function runTest() {
e.preventDefault();
describe("Simple assert", function() {
it("foo != bar", function() {
assert('foo' != 'bar', 'foo is not bar');
});
it('should return true if field is valid', function(){
var isValidText = isValidField('text');
var isValidNumber = isValidField('number');
assert.equal(isValidText, true);
assert.equal(isValidNumber, true);
});
return false;
});
}
or
function runTest() {
var validate = 'true';
describe("Simple assert", function() {
it("foo != bar", function() {
assert('foo' != 'bar', 'foo is not bar');
});
it('should return true if field is valid', function(){
var isValidText = isValidField('text');
var isValidNumber = isValidField('number');
assert.equal(isValidText, true);
assert.equal(isValidNumber, true);
});
validate = 'false';
});
alert(validate)
if(validate=='false'){
return false;
}
}
edited Nov 20 at 7:28
answered Nov 20 at 7:26
JIJOMON K.A
570119
570119
That didn't work unfortunately.
– Steve
Nov 20 at 7:28
please try my second ans, I add a code to alert the value of the variable validate. so you can easy to check
– JIJOMON K.A
Nov 20 at 7:29
Tried the second code, and no alert occurred?
– Steve
Nov 20 at 7:34
@Steve : Then there is an error in the above codes. please add an alert() in function top. and also check your script path is correct
– JIJOMON K.A
Nov 20 at 7:35
I've added an alert just inside runTest() and it doesn't fire. I have the path correct I believe.
– Steve
Nov 20 at 7:40
add a comment |
That didn't work unfortunately.
– Steve
Nov 20 at 7:28
please try my second ans, I add a code to alert the value of the variable validate. so you can easy to check
– JIJOMON K.A
Nov 20 at 7:29
Tried the second code, and no alert occurred?
– Steve
Nov 20 at 7:34
@Steve : Then there is an error in the above codes. please add an alert() in function top. and also check your script path is correct
– JIJOMON K.A
Nov 20 at 7:35
I've added an alert just inside runTest() and it doesn't fire. I have the path correct I believe.
– Steve
Nov 20 at 7:40
That didn't work unfortunately.
– Steve
Nov 20 at 7:28
That didn't work unfortunately.
– Steve
Nov 20 at 7:28
please try my second ans, I add a code to alert the value of the variable validate. so you can easy to check
– JIJOMON K.A
Nov 20 at 7:29
please try my second ans, I add a code to alert the value of the variable validate. so you can easy to check
– JIJOMON K.A
Nov 20 at 7:29
Tried the second code, and no alert occurred?
– Steve
Nov 20 at 7:34
Tried the second code, and no alert occurred?
– Steve
Nov 20 at 7:34
@Steve : Then there is an error in the above codes. please add an alert() in function top. and also check your script path is correct
– JIJOMON K.A
Nov 20 at 7:35
@Steve : Then there is an error in the above codes. please add an alert() in function top. and also check your script path is correct
– JIJOMON K.A
Nov 20 at 7:35
I've added an alert just inside runTest() and it doesn't fire. I have the path correct I believe.
– Steve
Nov 20 at 7:40
I've added an alert just inside runTest() and it doesn't fire. I have the path correct I believe.
– Steve
Nov 20 at 7:40
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53387759%2fform-onsubmit-return-function-but-form-still-submitting-and-page-reloading%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown