Intellipaat Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in Web Technology by (7k points)

I have a form that must execute a javascript function on submit, the function then posts data to PHP send mail file and the mail is sent. But it is only working in firefox and does not seem to be doing anything in IE, my question is: Is this the correct way to call a function from an external file from the form action:

action=”javascript:simpeCart.checkout()”

simpleCart is the .js file and checkout() is the function.

It is working fine in firefox but not in IE, chrome or safari.

<form name=form onsubmit="return validateFormOnSubmit(this)" enctype="multipart/form-data" action="javascript:simpleCart.checkout()" method="post">

1 Answer

0 votes
by (13.1k points)

A form action that is set to a JavaScript function is not widely supported.

The best you can do form action PHP script; if you need to do anything before submission you can just add it to onsubmit

function validateFormOnSubmit(theForm) {

    var reason = "";

    reason += validateName(theForm.name);

    reason += validatePhone(theForm.phone);

    reason += validateEmail(theForm.emaile);

    if (reason != "") {

        alert("Some fields need correction:\n" + reason);

    } else {

        simpleCart.checkout();

    }

    return false;

}

Then in your form:

<form action="#" onsubmit="return validateFormOnSubmit(this);">

Check out the Full Stack Developer course from Intellipaat.

Related questions

0 votes
1 answer
0 votes
1 answer
0 votes
1 answer
0 votes
1 answer
0 votes
1 answer

31k questions

32.8k answers

501 comments

693 users

Browse Categories

...