generating textfields dynamically
hiii,
i have a doubt.
if i write
<input name="<%=abcd%>" type="text" value="" size="6" class="TxtBox">
here the text field name comes dynamically. the name can vary.
i have to find the length of the particular name.
suppose the textfield contains 3 names namely CCA,HRA,XYZ.These 3 are coming from array list .i have to find the length of the each field individually.how can i get it.
i did like this.
i have passed name and index in the function like
fnTest('<%=abcd%>','<%=index%>')
in function it is displaying names.but how to fund the length i am not getting.
if any body knows tell me.
[695 byte] By [
pavuluria] at [2007-10-2 12:14:56]

javascriptdocument.forms[0].<%=abcd%>.value.length
it is not working. i want to find the length of each CCA,HRA,XYZ. suppose ther are 4 textfirleds that are dynamically generated, then i want to get the length for each CCA=4,HRA=4 & XYZ=4.
<%@ page contentType="text/html;charset=windows-1252"%>
<%
String name[] = {"CCA","HRA","XYZ"};
%>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
<title>untitled</title>
<script language="javascript">
function fnTest(name,x){
alert(eval("document.sample."+name+".value.length"));
}
</script>
</head>
<body>
<form name="sample">
<%for(int x=0;x<3;x++){%>
<input type="text" name="<%=name[x]%>" onblur="fnTest('<%=name[x]%>','<%=x%>') " size="6" />
<%}%>
</form>
</body>
</html>
i don't know the names .the names may change.some times it might be CCA.some can add new fields also.
so i can't take them as a fixed one.
the name that i am passing contains any number of names like cca,hra,..etc.they are not fixed.it may contain these names or it might not.
that's why i have to find all the length of the fields that are generated.
hiiiii,the code by 'jgalacambra' will work. same way u can apply different Styles, width to separate Textbox.improving.......................... ? ;-)are u doing any Project?AE
yes i am doing project.i am just learning java script.
hii,"all the best"u ll get sample codes from http://javascript-2.com http://dynamicdrive.comAE
hii,
thanx
i am not getting the above one. can u guide me.
first the earnings names are taken in a bean like
hmBean.put("alEmpHmEarnings",alEmpHmEarnings);
next the names occur with
strEarHeaderName=(String)((HashMap)alEmpHmEarnings.get(i)).get("er_name");
in jsp like above the code is written by checking some conditions.
hence the strEarHeaderName may contain either one earning,or no earnings,or more than one earning.
that earning may be any one.Depending on the conditions it will display CCA,or HRA or TAW
it can also display only one like CCA and the like
and the text is written like
<input type="text" name="<%=strEarHeaderName%>" value="" size="6" clas="TxtBox">
i tried like this,
<input type="text" name="<%=strEarHeaderName%>" value="" size="6" clas="TxtBox" onClick="fnTest('<%=strEarHeaderName%>','<%=index%>'>
the index is taken above .it is incrementing
function fnTest(earname,str)
{
alert(earname);
alert(str);
alert(form1.earname.length);
}
it is displaying earname,str.
But it is not displaying the 'earname.length'
how i can get the length of the earname.
the earname contains more than one name.
can u tell me how can i get the length of the each earning individually
and also total length.">
hii,
use
alert([b]eval[/b]("document.[b]form1[/b]."+earname+".value.length"));
if form1 is ur form name.
From my understanding earname getting only one value per time.
in ur post, mentioned about total length. what is that?
May i know the Logic behind this?
AE
alert(eval("document.form1."+earname+".value.length"));oralert( document.form1[earname].value.length );AE
total length means if earnings are of more than 2 like earnings of an employee can be in the form like child care allowance(CCA),
house rent allowance(HRA) ,Travel Allowance(TAW) like that.
Based On the person's salary his earnings will be there.
for some employees company can pay travel allowance,houserent allowance..etc
and for some it may not.
if employee contains earnings like CCA and HRA and TAW,then these three names of textfields are dynamically generated and the names can get through<%=strEarHeaderName%>.From this i have to identify the names and i have to find the lengths.
total length means the length of CCA,HRA,TAW .
suupose there are 3 textfields for the three then the length should be displayed as 9.
(or)
for individually it should be displayed as 3 for the earning name that is displayed.
hii,
is this u required?
<%@ page contentType="text/html;charset=windows-1252"%>
<%
String name[] = {"CCA","HRA","XYZ"};
%>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
<title>untitled</title>
<script language="javascript">
var total = 0;
function fnTest(name,x){
alert( "Individual length : " + document.sample[name].value.length );
total = total + document.sample[name].value.length ;
alert( "Total Length : " + total );
}
</script>
</head>
<body>
<form name="sample">
<%for(int x=0;x<3;x++){%>
<input type="text" name="<%=name[x]%>" onblur="fnTest('<%=name[x]%>','<%=x%>') " size="6" />
<%}%>
</form>
</body>
</html>
;-)
no, i want the length of the textboxes that are generated with CCA, HRA and TAW.not the length of the value.
Dear,
This creates complecation.
Pls tell me this
Suppose u have 3 txtboxes say, HRA, DA, LTA, and the Textbox size are 6,5,6 respectively. and values are 5000,300,4000 res'ly
Menu
*******
1. i want total length of all 3 textbox values.
{ 5000+300+4000}
2. i want total size of all textboxes.
{6+5+6}
3. i want total length of name of all textboxes
{4+3+4}
Enter ur choice :
AE
i got the length by using document.form1[earname].length;
can u tell me how i can get focus from one textbox to another textbox
by pressing enter key
suppose
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<HEAD>
<TITLE> New Document </TITLE>
<META NAME="Generator" CONTENT="EditPlus">
<META NAME="Author" CONTENT="">
<META NAME="Keywords" CONTENT="">
<META NAME="Description" CONTENT="">
</HEAD>
<SCRIPT language="Javascript">
function fnTest(earname,str)
{
alert("hi..");
var count = document.formHeader[earname].length;
alert(count);
if(event.keyCode==13) {
for(var i=parseInt(str)+1;i<count+1;i++) {
if(i!=count)
{
if(!formHeader[earname(i)].disabled)
{
formHeader[earname(i)].focus();
break;
}//end of if
}//end of if
}//end of for loop
return false;
}// end of event.keycode==13
}//end of if function
></SCRIPT>
<BODY>
<FORM name="formHeader">
<CENTER>
<%
for(int i=0;i<5;i++)
{
%>
box:<input type="text" name="box" onkeyDown="javascript:return fnTest('box','<%=i%>');">
<!--box1:<input type="text" name="box1" onclick="fnTest('box1','<%=i%>'>-->
<%}
%>
</CENTER>
<input type="hidden" name="boxCount" value="5"/>
</FORM>
</BODY>
</HTML>
here i have to focus from one text box to another
i wrote forformHeader[earname(i)].focus();
but it is not working
how i can write
this one.
[nobr]Dear,
That i have mentioned Before....
ok .
may i know ur good name pls.
ok fine. here is the code.
Check the Changes
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<HEAD>
<TITLE> New Document </TITLE>
<META NAME="Generator" CONTENT="EditPlus">
<META NAME="Author" CONTENT="">
<META NAME="Keywords" CONTENT="">
<META NAME="Description" CONTENT="">
</HEAD>
<SCRIPT language="Javascript">
function fnTest(earname,str, totalnos)
{
//alert("hi.."+ event.keyCode );
var ctl = "" + earname + "" + str;
var count = document.formHeader[ctl].length;
//alert(count);
if(event.keyCode==13) {
if( parseInt(totalnos - 1 ) == parseInt(str) )
{
var ctrl = "" + earname + "0";
document.formHeader[ctrl].focus();
}
else
{
var ctrl = "" + earname + "" + ( parseInt(str) +1 );
document.formHeader[ctrl].focus();
}
}
}//end of if function
</SCRIPT>
<BODY>
<FORM name="formHeader">
<CENTER>
<%
for(int i=0;i<5;i++)
{
%>
box:<input type="text" name="box<%=i%>" onkeyDown="javascript:return fnTest('box','<%=i%>', 5);"/><br>
<!--box1:<input type="text" name="box1" onclick="fnTest('box1','<%=i%>'>-->
<%}
%>
</CENTER>
<input type="hidden" name="boxCount" value="5"/>
</FORM>
</BODY>
</HTML>
AE[/nobr]
y u want u to knopw my name
it's hard to Pronounce "PAVULURI'.Name is not a big matter. Try to complete the thread firstAE
[nobr]hi,
According to my understanding u have 2 more Questions to ask
1. if there is no value in textbox, 0 should be placed.
2. if some disabled text box are there, there should be a management for this
and the code is.....
This is the answer for ur next Question : ie Zero values
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<HEAD>
<TITLE> New Document </TITLE>
<META NAME="Generator" CONTENT="EditPlus">
<META NAME="Author" CONTENT="">
<META NAME="Keywords" CONTENT="">
<META NAME="Description" CONTENT="">
</HEAD>
<SCRIPT language="Javascript">
function fnTest(earname,str, totalnos)
{
//alert("hi.."+ event.keyCode );
var ctl = "" + earname + "" + str;
var count = document.formHeader[ctl].length;
//alert(count);
if(event.keyCode==13) {
if( parseInt(totalnos - 1 ) == parseInt(str) )
{
var ctrl = "" + earname + "0";
document.formHeader[ctrl].focus();
}
else
{
var ctrl = "" + earname + "" + ( parseInt(str) +1 );
document.formHeader[ctrl].focus();
}
}
}//end of if function
function ckeckZeros( ctrl )
{
if( ctrl.value == "" )
ctrl.value = 0;
}
function ckeck4Zeros( ctrl )
{
if( ctrl.value == "0" )
ctrl.value = "";
}
</SCRIPT>
<BODY>
<FORM name="formHeader">
<CENTER>
<%
for(int i=0;i<5;i++)
{
%>
box:<input type="text" name="box<%=i%>" value="0" onfocus="Javascript:ckeck4Zeros(this);" onblur="Javascript:ckeckZeros(this);" onkeyDown="javascript:return fnTest('box','<%=i%>', 5);"/><br>
<%}
%>
</CENTER>
<input type="hidden" name="boxCount" value="5"/>
</FORM>
</BODY>
</HTML>
and finally for Disabled textbox Problem
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<HEAD>
<TITLE> New Document </TITLE>
<META NAME="Generator" CONTENT="EditPlus">
<META NAME="Author" CONTENT="">
<META NAME="Keywords" CONTENT="">
<META NAME="Description" CONTENT="">
</HEAD>
<SCRIPT language="Javascript">
function fnTest(earname,str, totalnos)
{
//alert("hi.."+ event.keyCode );
var ctl = "" + earname + "" + str;
var count = document.formHeader[ctl].length;
//alert(count);
if(event.keyCode==13) {
if( parseInt(totalnos - 1 ) == parseInt(str) )
{
var ctrl = "" + earname + "0";
if( document.formHeader[ctrl].disabled == true )
{
fnTest( earname, 1 , totalnos );
}
else
{
document.formHeader[ctrl].focus();
}
}
else
{
var ctrl = "" + earname + "" + ( parseInt(str) +1 );
if( document.formHeader[ctrl].disabled == true )
{
fnTest( earname, parseInt(str) +1 , totalnos );
}
else
{
document.formHeader[ctrl].focus();
}
}
}
}//end of if function
function ckeckZeros( ctrl )
{
if( ctrl.value == "" )
ctrl.value = 0;
}
function ckeck4Zeros( ctrl )
{
if( ctrl.value == "0" )
ctrl.value = "";
}
</SCRIPT>
<BODY>
<FORM name="formHeader">
<CENTER>
<%
for(int i=0;i<5;i++)
{
%>
box:<input type="text" name="box<%=i%>" value="0" onfocus="Javascript:ckeck4Zeros(this);" onblur="Javascript:ckeckZeros(this);" onkeyDown="javascript:return fnTest('box','<%=i%>', 5);"/><br>
<%}
%>
</CENTER>
<input type="hidden" name="boxCount" value="5"/>
</FORM>
<SCRIPT language="Javascript">
//Disable Text box code here
document.formHeader.box0.disabled = true;
document.formHeader.box1.disabled = true;
document.formHeader.box3.disabled = true;
</script>
</BODY>
</HTML>
AE[/nobr]
that disabled one is for another jsp. any way thanx.u helped me a lot.once again thank u.
sorry once again i am troubling you
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<HEAD>
<TITLE> New Document </TITLE>
<META NAME="Generator" CONTENT="EditPlus">
<META NAME="Author" CONTENT="">
<META NAME="Keywords" CONTENT="">
<META NAME="Description" CONTENT="">
</HEAD>
<SCRIPT language="Javascript">
function fnTest(earname,str)
{
}//end of function
</SCRIPT>
<BODY>
<FORM name="formHeader" >
<CENTER>
<INPUT TYPE="checkbox" name="checkbox">
<INPUT TYPE="TEXT" name="box" value="1" disabled="true" onKeyDown="javascript:return fnTest('box','0');">
<INPUT TYPE="checkbox" name="checkbox">
<INPUT TYPE="TEXT" name="box" value="2" onKeyDown="javascript:return fnTest('box','1');">
<INPUT TYPE="checkbox" name="checkbox">
<INPUT TYPE="TEXT" name="box" value="0" disabled onKeyDown="javascript:return fnTest('box','2');">
<INPUT TYPE="checkbox" name="checkbox">
<INPUT TYPE="TEXT" name="box" value="" onKeyDown="javascript:return fnTest('box','3');">
<INPUT TYPE="checkbox" name="checkbox">
<INPUT TYPE="TEXT" name="box" value="" onKeyDown="javascript:return fnTest('box','4');">
<INPUT TYPE="checkbox" name="checkbox">
<INPUT TYPE="TEXT" name="box" value="" onKeyDown="javascript:return fnTest('box','5');">
<INPUT TYPE="checkbox" name="checkbox">
<INPUT TYPE="TEXT" name="box" value="" onKeyDown="javascript:return fnTest('box','6');">
<INPUT TYPE="checkbox" name="checkbox">
<INPUT TYPE="TEXT" name="box" value="12" disabled="true" onKeyDown="javascript:return fnTest('box','7');">
<INPUT TYPE="checkbox" name="checkbox">
<INPUT TYPE="TEXT" name="box" value="" onKeyDown="javascript:return fnTest('box','8');">
<INPUT TYPE="checkbox" name="checkbox">
<INPUT TYPE="TEXT" name="box" value="" onKeyDown="javascript:return fnTest('box','9');">
<INPUT TYPE="checkbox" name="checkbox">
<INPUT TYPE="TEXT" name="box" value="" onKeyDown="javascript:return fnTest('box','10');">
<!--<img src="../images/bt_submitsmall.jpg" border="0" width="64" height="21" name="done">-->
</CENTER>
<!--<input type="hidden" name="boxCount" value="11"/>-->
</FORM>
</BODY>
</HTML>
the code u have sent is not working if there are some disabled firelds.
if there are disabled fields then the focus must go tom the next enabled field.
[nobr]Dear Pavu,
The code i sent was alreadry Tested.
Here is that again
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<HEAD>
<TITLE> New Document </TITLE>
<META NAME="Generator" CONTENT="EditPlus">
<META NAME="Author" CONTENT="">
<META NAME="Keywords" CONTENT="">
<META NAME="Description" CONTENT="">
</HEAD>
<SCRIPT language="Javascript">
function fnTest(earname,str, totalnos)
{
//alert("hi.."+ event.keyCode );
var ctl = "" + earname + "" + str;
var count = document.formHeader[ctl].length;
//alert(count);
if(event.keyCode==13) {
if( parseInt(totalnos - 1 ) == parseInt(str) )
{
var ctrl = "" + earname + "0";
if( document.formHeader[ctrl].disabled == true )
{
fnTest( earname, 1 , totalnos );
}
else
{
document.formHeader[ctrl].focus();
}
}
else
{
var ctrl = "" + earname + "" + ( parseInt(str) +1 );
if( document.formHeader[ctrl].disabled == true )
{
fnTest( earname, parseInt(str) +1 , totalnos );
}
else
{
document.formHeader[ctrl].focus();
}
}
}
}//end of if function
function ckeckZeros( ctrl )
{
if( ctrl.value == "" )
ctrl.value = 0;
}
function ckeck4Zeros( ctrl )
{
if( ctrl.value == "0" )
ctrl.value = "";
}
</SCRIPT>
<BODY>
<FORM name="formHeader">
<CENTER>
<%
for(int i=0;i<5;i++)
{
%>
box:<input type="text" name="box<%=i%>" value="0" onfocus="Javascript:ckeck4Zeros(this);" onblur="Javascript:ckeckZeros(this);" onkeyDown="javascript:return fnTest('box','<%=i%>', 5);"/><br>
<!--box1:<input type="text" name="box1" onclick="fnTest('box1','<%=i%>'>-->
<%}
%>
</CENTER>
<input type="hidden" name="boxCount" value="5"/>
</FORM>
<SCRIPT language="Javascript">
//Disable Text box code here
document.formHeader.box0.disabled = true;
document.formHeader.box1.disabled = true;
document.formHeader.box3.disabled = true;
</script>
</BODY>
</HTML>
here
document.formHeader.box0.disabled = true;
document.formHeader.box1.disabled = true;
document.formHeader.box3.disabled = true;
are code to disable text boxes
;-)
AE[/nobr]
Pavu,Check the previous code Once more. and let us know.AE
it is working. thanx. sorry ,yesterday i was not there.that's y i didn't gave reply
hii,ok, fine...Bye bye ;-)AE