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!

Dynamic query - Javascript question

Status
Not open for further replies.

modfather

MIS
Feb 15, 2000
75
US
Folks,

This problem is directly a Javascript question, but ColdFusion is involved too. In the example below #currentRow# is the row number I’m on as I cycle through a CFQUERY using CFLOOP. I loop through, creating multiple text box controls for every item in my table. Everything seems to work well, except the “&&” in my Javascript function doesn’t seem to be recognized. Here’s my code:

In my <HEAD> area I have:

<script language=&quot;JavaScript&quot;>
function myTest(n) {
var currentqty = eval('document.form1.quantity' + n).value;
var currentinc = eval('document.form1.increment' + n).value;

if((currentinc != 0) && (currentqty % currentinc != 0)) {
alert(&quot;You must order this part in increments of &quot; + currentinc + &quot; (&quot; + currentinc + &quot;, &quot; + (currentinc*2) + &quot;, &quot; + (currentinc*3) + &quot;...)&quot;);
}
}

In my <BODY>:

<input name=&quot;quantity#currentrow#&quot; type=&quot;text&quot; class=&quot;font003&quot; value=&quot;0&quot; size=&quot;3&quot; onChange=&quot;myTest(#currentRow#);&quot;

The problem seems to be the &quot;&&&quot; portion of the code. I'm (obviously) not a huge JS programmer, but I've tried many different combinations (just checking the first part of the &quot;if&quot; statement which works fine, etc) It definitely seems like the &quot;&&&quot; isn't being evaluated correctly...

The error I get just says &quot;Syntax Error&quot;, but the line/position point right to the &quot;&&&quot;... Arrgh!

Any help would be VERY appreciated!

Thanks!
Steve
 
I don't see any problem with the if statement but I do see a problem with the eval statements.

eval is a function that takes a string as an argument. So the syntax is

Code:
eval( &quot;a string of stuff that should be javascript&quot; )

So this is probably what you want
Code:
eval('document.form1.increment' + n + '.value')

Anyway make those two changes and see if the error disappears.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top