Discussion Locked

parameters usage in javascript

0 helpful
3 replies
Closed to new repliesThis discussion is closed. It stays readable, but it takes no new replies.

i am stuck with an situation i give the code here.
parameters sent from function is working in alert nicely but it is not woring in if condition (document.f1.cmb....)

kindly study & help me out.

regards

3 replies

by shanghai sam

It appears you're trying to check the value of a SELECT element, then removing focus from some other element based on the value. This seems strang to me, but I'm sure you have a higher purpose in mind...

Anyway, it looks like your parentheses aremismatched on a couple of lines, and you're trying to access a string as if it were and object. Try this:

function checkcmb(i)
{
var element1 = eval('document.f3.recmb' + i);
var element2 = eval('document.f3.noofret' + i);
if (element1.selectedIndex == 1)
element2.blur();
}

I used the eval function to convert the constructed string to an object reference for each element. One final note: the selectedIndex attribute is zero-based. Your code actually looks for the second item in the list (index 1).

Hope this helps.

This discussion is closed to new replies.