Copy link to clipboard
Copied
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
Copy link to clipboard
Copied
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.
Copy link to clipboard
Copied
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.
Copy link to clipboard
Copied
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.
Copy link to clipboard
Copied
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:
function testresults() {
;
if (form.species1.value != "Tarpon") {
g=Math.pow(10,(loga+(bMath.log(form.length.value 25.4)/Math.log(10))));
pounds=parseInt(g*0.0022046);
ounces=Math.round(((g0.0022046)-pounds)16);
form.pounds.value=pounds;
form.ounces.value=ounces;
}
else {
kg=Math.pow(10,loga+b(Math.log((form.length.value25.4)*0.8961-10.2192)/Math.log(10)));
pounds=parseInt(kg*2.204622341);
ounces=Math.round(((kg2.204622341)-pounds)16);
form.pounds.value=pounds;
form.ounces.value=ounces;
}
return;
}
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.
Copy link to clipboard
Copied
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
Copy link to clipboard
Copied
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.
Copy link to clipboard
Copied
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)));
Copy link to clipboard
Copied
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):
Copy link to clipboard
Copied
The thing is though that whilst IE announces JavaScript errors with a very obvious pop-up, Firefox just writes errors to its log. Did you check the error log to confirm there's not also a JS error in Firefox?
--
Adam
Copy link to clipboard
Copied
I didn't know about the error log, but it helped find some syntax errors. Didn't solve my problem, though. After fooling around with it all morning, this is what I found: If all the functions are within one script tag, they do not work in FF or IE until the form is submitted. Then it works in both browsers just fine. Before hitting the submit button, I get "function() not defined" in FF and "object expected" in IE when I click any button. Seems like the functions are defined only after the form is submitted.
However, if I put each function under separate script tags, everything works fine in FF with no errors, and nothing works in IE with "object expected" error. Any suggestions?