Skip to main content
Participant
July 29, 2014
Answered

CFFORM onSubmit script works in FF but not in IE

  • July 29, 2014
  • 2 replies
  • 917 views

I've got a CFFORM that has an onSubmit additional javascript for  form validation, and while it works in FF, it passes right through in IE and ends up erroring because the mandatory fields aren't there...

the CFFORM call looks like this

<cfform name="add_project" method="post" action="xxxxxxx.cfm?view=admin-add-process&entity=project" enctype="multipart/form-data" onsubmit="return checkReq();">

and the function looks like

<script language="javascript">

function checkReq() {

var valid = true;

var errMsg = '';

if (document.add_project.projectreviewer_emails.value.trim() == '') {

...

} else {

...

}

...

</script>

Any ideas?

Thanks in advance,

bw

    This topic has been closed for replies.
    Correct answer BKBK

    There is some doubt regarding the universality of Javascript's trim function among browsers. Is it vital here?  If you leave it out, your code will work across all browsers. Something along the lines of:

    <script type="text/javascript">

    function checkReq() {

        var valid = true;

        var errMsg = '';

        var projectReviewerEmails = document.forms["add_project"]["projectreviewer_emails"].value;

        if (projectReviewerEmails == '') {

            // no no no no no

            return !valid;

        } else {

            // yeah yeah yeah yeah yeah

            return valid;

        }

    }

    </script>

    <cfform name="add_project" method="post" action="test.cfm?view=admin-add-process&entity=project" enctype="multipart/form-data" onsubmit="return checkReq();">

    <cfinput type="file" name="projectreviewer_emails" >

    <cfinput type="submit" name="sbmt" value="Submit">

    </cfform>

    2 replies

    BKBK
    Community Expert
    BKBKCommunity ExpertCorrect answer
    Community Expert
    July 30, 2014

    There is some doubt regarding the universality of Javascript's trim function among browsers. Is it vital here?  If you leave it out, your code will work across all browsers. Something along the lines of:

    <script type="text/javascript">

    function checkReq() {

        var valid = true;

        var errMsg = '';

        var projectReviewerEmails = document.forms["add_project"]["projectreviewer_emails"].value;

        if (projectReviewerEmails == '') {

            // no no no no no

            return !valid;

        } else {

            // yeah yeah yeah yeah yeah

            return valid;

        }

    }

    </script>

    <cfform name="add_project" method="post" action="test.cfm?view=admin-add-process&entity=project" enctype="multipart/form-data" onsubmit="return checkReq();">

    <cfinput type="file" name="projectreviewer_emails" >

    <cfinput type="submit" name="sbmt" value="Submit">

    </cfform>

    Participating Frequently
    July 30, 2014

    What does the input field projectreviewer_emails look like in your HTML?

    What do you get if you do

    • console.log(document.add_project.projectreviewer_emails.value);
    • console.log(document.add_project.projectreviewer_emails);
    • console.log(document.add_project);

    PS: the language attribute on <script> has been deprecated since 1999, change it to

    <script type="text/javascript">

    or even just

    <script>