Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • EspaƱol
      • FranƧais
      • PortuguĆŖs
  • ę—„ęœ¬čŖžć‚³ćƒŸćƒ„ćƒ‹ćƒ†ć‚£
  • ķ•œźµ­ ģ»¤ė®¤ė‹ˆķ‹°
0

CFFORM onSubmit script works in FF but not in IE

Explorer ,
Jul 29, 2014 Jul 29, 2014

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

819
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Community Expert , Jul 30, 2014 Jul 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 {

        // ye

...
Translate
Engaged ,
Jul 30, 2014 Jul 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>

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jul 30, 2014 Jul 30, 2014
LATEST

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>

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Resources