Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Using simple Javascript from within <CFORM><CFINPUT>

Status
Not open for further replies.

doco

Programmer
Sep 28, 2000
32
GB
Hi, I am trying to display a totalised set of 5 values taken from 5 <cfinput> tags so it shows up in a javascript alert message box. the code worked ok just using
standard html <form> and <input> tags on netscape 4.7 browsers. However IT DONT WORK when i use <cfform> and <cfinput> tags as I get a javascript error. though it seems
to work ok in Internet explorer.

I'm pretty new to javascript so if you can tell me what I'm doing wrong and maybe advise on a better way of doing it, i wud be truly grateful

please see listing below:

Chris

<html>
<head>
<title>Total User Input Using Javascript</title>

<SCRIPT LANGUAGE = &quot;JavaScript&quot;>
function pressed(){
var tote1=parseInt(SetActive.qty1.value);
var tote2=parseInt(SetActive.qty2.value);
var tote3=parseInt(SetActive.qty3.value);
var tote4=parseInt(SetActive.qty4.value);
var tote5=parseInt(SetActive.qty5.value);
var tote = tote1+tote2+tote3+tote4+tote5
alert(&quot;Total for this fixing =&quot;+tote)
}
</script>
</head>

<body>
<cfFORM name =&quot;SetActive&quot; ACTION=&quot;myURL&quot; METHOD=&quot;POST&quot;>

QTY1<cfINPUT TYPE =&quot;TEXT&quot; NAME = &quot;qty1&quot; value = &quot;0&quot;><br>
QTY2<cfINPUT TYPE =&quot;TEXT&quot; NAME = &quot;qty2&quot; value = &quot;0&quot;><br>
QTY3<cfINPUT TYPE =&quot;TEXT&quot; NAME = &quot;qty3&quot; value = &quot;0&quot;><br>
QTY4<cfINPUT TYPE =&quot;TEXT&quot; NAME = &quot;qty4&quot; value = &quot;0&quot;><br>
QTY5<cfINPUT TYPE =&quot;TEXT&quot; NAME = &quot;qty5&quot; value = &quot;0&quot;>


<input type =&quot;button&quot; name=&quot;totebutton&quot; value = &quot;check totals&quot; onClick=&quot;pressed()&quot;>

</cfform>

</body>
</html>
 
in order to make your script work in Netscape, you have to add correct your JavaScript function as follow:

function pressed(){
var tote1=parseInt(document.SetActive.qty1.value);
var tote2=parseInt(document.SetActive.qty2.value);
var tote3=parseInt(document.SetActive.qty3.value);
var tote4=parseInt(document.SetActive.qty4.value);
var tote5=parseInt(document.SetActive.qty5.value);
var tote = tote1+tote2+tote3+tote4+tote5
alert(&quot;Total for this fixing =&quot;+tote)
} Sylvano
dsylvano@hotmail.com

&quot;every and each day when I learn something new is a small victory...&quot;
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top