sachin dubey sachin dubey - 3 years ago 219
Javascript Question

how to stay on same page after alert in JavaScript

it shows alert if it is blank but it goes to next page("action=some.php") so any idea how to be on same page after alert?

function validateForm() {
var x = document.forms["uploadForm"]["userImage"].value;
if (x == "") {
alert("Choose the file !!!!!");
return false;
var p = document.forms["uploadForm"]["Start_Date"].value;
var q = document.forms["uploadForm"]["End_Date"].value;
if (p == "" && q=="") {
alert("Select the date !!!!!");
return false;
var radio = document.forms["uploadForm"]["radio"].value;
if (radio == "") {
alert("Select the Radio !!!!!");
return false;

Answer Source

I used onClick="return validateForm()" in place of onClick=validateForm(). Thank you so much @epascarello for your quick answer.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download