Skip to main content
Participating Frequently
March 31, 2011
Question

cfforms, cfinputs, onclick, ie

  • March 31, 2011
  • 3 replies
  • 2287 views

I am building a website for the first time, so I don't know alot yet.  I have a form with cfinput buttons that call functions onClick.  It works in FF but not in IE.  I get the error "object expected" when it gets to the function() part.  I created a simple way to test it.

Can you tell me why this works in IE

<head>
<script type="text/javascript">
function testresults() {

    alert ("You typed: ");
}
</script>

</head>

<body>
<input type="button" name="test1" id="test1" onClick="testresults()">
</body>

but this does not work in IE?

<head>
<script type="text/javascript">
function testresults() {

    alert ("You typed: ");
}
</script>

</head>

<body>

<cfform>

</cfform>
<input type="button" name="test1" id="test1" onClick="testresults()">
</body>

What do I need to do to make it work in IE?

By the way, I'm using Dreamweaver CS4, Coldfusion 9, Windows XP and IE8.

Brenda

    This topic has been closed for replies.

    3 replies

    Participating Frequently
    April 1, 2011

    For some reason that last post didn't come out right. Try again.

    I must be losing my mind because I swear that yesterday I tried every way, including putting the input statement within the cfform tags and using cfinput within the tags and all I got were errors.  Now today for some reason, it works just fine.

    I still can't get my web page to work so I sending some of the code and maybe someone can tell me what I'm doing wrong.

    The scripts:

    <script type="text/javascript">

    function testresults() {

    <!--    var TestVar = document.form.length.value;

        alert ("You typed: ");

    }

    function ClearForm(form){

        form.length.value = "";

        form.pounds.value = "";

        form.ounces.value = "";

          form.species1.selectedIndex=0;

    }

    function checkform(form) {

           if (form.species1.selectedIndex <= 0) {

                            alert("Please select a species!");

                            return false;

    }

           else if (form.length.value==null||form.length.value.length==0) {

                alert("Please enter length in inches!");

                return false;

           }

             else if (parseFloat(form.length.value) <= 0||

                    parseFloat(form.length.value) >=180) {

                    alert("Please choose a number between minimum \and maximum values!");

                    ClearForm(form);

                    return false;

           }

                return true;

    }

    function computeform(form) {

                loga=<cfoutput>#lengthweight1.logavalue#</cfoutput>;

                b=<cfoutput>#lengthweight1.bvalue#</cfoutput>;

    if (form.species1.value != "Tarpon") {

                g=Math.pow(10,(loga+(b*Math.log(form.length.value*          25.4)/Math.log(10))));

                pounds=parseInt(g*0.0022046);

                ounces=Math.round(((g*0.0022046)-pounds)*16);

           form.pounds.value=pounds;

             form.ounces.value=ounces;

             }

    else   {

                kg=Math.pow(10,loga+b*(Math.log((form.length.value*25.4)*0.8961-10.2192)/Math.log(10)));

             pounds=parseInt(kg*2.204622341);

             ounces=Math.round(((kg*2.204622341)-pounds)*16);

           form.pounds.value=pounds;

             form.ounces.value=ounces;

           }

           return;

    }

    </SCRIPT>

    Within the cfform tags:

    <p align="center">

    <cfinput type="submit" name="go" value="go" onClick="checkform(this.form)">

      <cfinput type="button" name="compute" value="Calculate weight"  onClick="computeform(this.form)">

      <cfinput type="button" name="reset" value="Reset" onClick="ClearForm(this.form)">

    <cfinput type="button" name="check" value="check" onClick="checkform(this.form)">

    <cfinput type="button" name="test" value="test" onClick="testresults()"></p>

    When I click any button, I get an error saying “Object expected” and points to the function() statement. Any suggestions?  This works fine in FF, just not in IE.

    Inspiring
    April 1, 2011

    This works fine in FF

    It does not work in either browser for me.

    Error: missing ) after argument list

    Line: 137, Column: 82

    Source Code:

    kg=Math.pow(10,loga+b(Math.log((form.length.value25.4)*0.8961-10.21 92)/Math.log(10)));

    Participating Frequently
    April 1, 2011

    This is what I get in FF after clicking "go" then "calculate weight":

    This is what I get in IE after clicking "go" (or any button):

    Inspiring
    April 1, 2011

    Form-control tags such as INPUT need to be within FORM tags for it to be well-formed mark-up.  If your mark-up isn't well-formed, JS behaviour will be erratic: some browsers will let you get away with things that other browsers do not.

    Check your mark-up on the validator @ W3C.

    --

    Adam

    Inspiring
    April 1, 2011

    You don't have a closing cfform tag that I see.  If it's later in your code, move it so that it comes before the closing body tag.

    Participating Frequently
    April 1, 2011

    There is a closing cfform, it's right above the input statement. For some reason, just having a cfform statement in the page makes IE stop running function(). Don't know why. Don't know how to get around it. Both set of statements work fine in FF.

    Inspiring
    April 1, 2011

    There is a closing cfform, it's right above the input

    statement. 

    It should not be above the input tag. As Adam mentioned, the input should be inside the form/cfform tags. As it is right now, your html is not well formed.