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 bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Passing Fields as Arguments to Function 1

Status
Not open for further replies.

Andrew888

Programmer
Oct 4, 2001
8
US
I'm totally not a Javascript person...so, maybe one of you can help me out. I'd appreciate it!

I've got this strange request that requires some validation. I will have on a web page an input box and another input box next to it. The user will type text in the first one, the second will count the number of characters. There will be up to 10 lines (so, 20 boxes total - 10 inputs and 10 inputs that display counts).

So, how can I accomplish this? I have:


<script language=&quot;javascript&quot;>
function countChars2(field1,field2) {
var myCount = eval('document.frmTest.' + field1 + '.value.length');
// How do I make text2 display myCount?
//I tried:
//document.frmTest.field2.value = myCount;
//but that did not work
return true;
}
</script>

<form name=&quot;frmTest&quot; id=&quot;frmTest&quot; action=&quot;test.asp&quot; method=&quot;post&quot;>
<input type=&quot;text&quot; size=&quot;55&quot; maxLength=&quot;50&quot; name=&quot;text1&quot; id=&quot;text1&quot; onKeyUp=&quot;countChars2('text1','text2')&quot;>
<input type=&quot;text&quot; size=&quot;10&quot; disabled name=&quot;text2&quot; id=&quot;text2&quot; value=&quot;0&quot;>
</form>

Any help will be greatly appreciated!

Thanks,
Andrew
 
try this:

<script language=&quot;javascript&quot;>
function countChars2(field1,field2) {
if (document.frmTest[field1].value) {
var myCount = document.frmTest[field1].value.length;
document.frmTest[field2].value = myCount;
}
return true;
}
</script>


=========================================================
while (!succeed) try();
-jeff
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top