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

input into text box with generated name

Status
Not open for further replies.

belocin

Programmer
Jul 10, 2000
12
US
Hi, I'm hoping someone can help me.
What I have is a form in an asp page that generates the name attribute of a text box. The text box has a default value of 0, I have a function that checks to make sure that there is some value in the box, but what I want to do is put a 0 back in if the field is left blank. The problem is I'm getting an error because the name is generated with text and a number. I can't figure out how to get the fieldname in the line of code: (document.projviewform.cat.value=fieldvalue;)

thanks for any help.

Here is the code I have:

<SCRIPT language=&quot;JavaScript&quot;>
function checkValue(fieldvalue,fieldname,counter)
{
alert(fieldvalue);
if (fieldvalue == &quot;&quot;)
{
fieldvalue = 0;
alert(fieldname+counter);
cat = fieldname+counter;
alert(cat);
document.projviewform.cat.value=fieldvalue;
}
}
</SCRIPT>

<form name=&quot;projviewform&quot; method=&quot;post&quot; action=&quot;test.asp&quot;>
<% For count = 0 to 1%>

<input onblur=&quot;checkValue(this.value,'passField',<%=count%>);&quot; type=&quot;Text&quot; name=&quot;passField<%=count%>&quot; value=&quot;0&quot;>

<%Next%>
</form>
 
Try this :

Code:
<SCRIPT language=&quot;JavaScript&quot;>
function checkValue(fieldvalue,fieldname,counter)
{
alert(fieldvalue);
if (fieldvalue == &quot;&quot;)
{
fieldvalue = 0;
alert(fieldname+counter);
cat = fieldname+counter;
alert(cat);
document.projviewform[fieldname].value=fieldvalue;
}
}
</SCRIPT>

<form name=&quot;projviewform&quot; method=&quot;post&quot; action=&quot;test.asp&quot;>
<% For count = 0 to 1%>

<input onblur=&quot;checkValue(this.value,'passField<%=count%>',<%=count%>);&quot; type=&quot;Text&quot; name=&quot;passField<%=count%>&quot; value=&quot;0&quot;>

<%Next%>
</form>
Regards

Big Bad Dave

davidbyng@hotmail.com
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top