January 2nd, 2001, 12:56 PM
-
I have following code. Its ok if i have only one City name and prov. name. Now i have changed that user can put in multiple City and state names. so every time txtMktCityName and txtMktPhyStateProv are changing to txtMktCityName0 and xtMktPhyStateProv0 and so on depending on the user how many values are being entered. so i was wondering how to write Java script so that code also changes dynamically as txt names are changed.
<SCRIPT Language="JavaScript">
function checkCityName(mthis)
{ if(mthis.txtMktCityName.value=="")
{
alert("Please Enter the Marketing City Name");
return false;
}
if(mthis.txtCountryCode.value=="1")
{
if(mthis.txtMktPhyStateProv.value=="")
{
alert("Please Enter the Mkt State Prov Name");
return false;
}
}
return true;
}
</SCRIPT>
Thanks
January 16th, 2001, 09:02 AM
-
I really don't know what you're meaning, but if it is to dynamically refer to formfields this is a way to do it:
<html>
<script>
function yeah( iElement ) {
alert("Value=" + document.frmYeah.elements["txtYeah" + iElement].value);
document.frmYeah.btn.focus();
}
</script>
<body bgcolor="#ffffff" text="#000000" id=all>
<form name="frmYeah">
<input onBlur="yeah(1)" name="txtYeah1"><br>
<input onBlur="yeah(2)" name="txtYeah2"><br>
<input type="submit" name="btn">
</form>
</body>
</html>
Here you can see that I use the 'elements' array with a composit string to refer to the element name ("txtYeah" + "1" e.g.)