Connecting Tech Pros Worldwide Forums | Help | Site Map

Dynamically create text boxes and add numbers

Newbie
 
Join Date: Nov 2006
Posts: 8
#1: Nov 28 '06
I require coding for adding text box and label box from the created button and then converting string value into integer from one text box to other.

Newbie
 
Join Date: Nov 2006
Posts: 8
#2: Nov 28 '06

re: Dynamically create text boxes and add numbers


I require coding for adding text box and label box from the created button and then converting string value into integer from one text box to other.
Newbie
 
Join Date: Nov 2006
Posts: 3
#3: Nov 28 '06

re: Dynamically create text boxes and add numbers


Could you be more specific? You want a button to create a textbox with a label? And then enter a string value into this box and convert it into an integer? Or you want to have a textbox with a label above it and when you hit the button, it will convert the value into an integer value?
Expert
 
Join Date: Oct 2006
Location: NC
Posts: 1,722
#4: Nov 28 '06

re: Dynamically create text boxes and add numbers


Please don't double post, also be more specific with what kind of help you need
Newbie
 
Join Date: Nov 2006
Posts: 8
#5: Nov 29 '06

re: Dynamically create text boxes and add numbers


i need to create the text boxes dynamically using an add button and to add the values entered in to those text boxes should be added immediately after entering the value. IN JAVA SCRIPT.
Newbie
 
Join Date: Nov 2006
Posts: 8
#6: Nov 29 '06

re: Dynamically create text boxes and add numbers


I need to create the text boxes dynamically using an add button and to add the values entered in to those text boxes should be added immediately after entering the value. IN JAVA SCRIPT.
Newbie
 
Join Date: Nov 2006
Posts: 1
#7: Nov 29 '06

re: Dynamically create text boxes and add numbers


how are you ???????
Lives Here
 
Join Date: Sep 2006
Posts: 12,070
#8: Nov 29 '06

re: Dynamically create text boxes and add numbers


Quote:

Originally Posted by ammupriya

I need to create the text boxes dynamically using an add button and to add the values entered in to those text boxes should be added immediately after entering the value. IN JAVA SCRIPT.

You need to write code for responding to onClick of button and either onblur or onChange of the textbox. If you had attempted this and posted some code first, I would have corrected it if neccessary.
Lives Here
 
Join Date: Sep 2006
Posts: 12,070
#9: Nov 29 '06

re: Dynamically create text boxes and add numbers


Quote:

Originally Posted by ammupriya

i need to create the text boxes dynamically using an add button and to add the values entered in to those text boxes should be added immediately after entering the value. IN JAVA SCRIPT.

One post per problem please
Newbie
 
Join Date: Nov 2006
Posts: 8
#10: Dec 1 '06

re: Dynamically create text boxes and add numbers


<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Add/Remove child: Javascript</title>
<script type="text/javascript">
<!--

function addEvent()
{
var ni = document.getElementById('myDiv');
var numi = document.getElementById('theValue');
var d=document.getElementById("thevalue");
var num = (document.getElementById("theValue").value -1)+ 2;
numi.value = num;
var divIdName = "my"+num+"Div";
var newdiv = document.createElement('div');
newdiv.setAttribute("id",divIdName);
newdiv.innerHTML = "Label "+num+" :";
newdiv.innerHTML+="<input type='text' name='quantity"+num+"' onBlur='countAll(this)' /> ";
newdiv.innerHTML+="<input type='hidden' name='hid"+num+"' value='' /> ";
newdiv.innerHTML+="<input type='button' name='del' value='Delete' onclick=\"removeEvent(\'"+divIdName+"\')\" >";
ni.appendChild(newdiv);
document.getElementById('quantity'+num).focus();
}

function trim(val)
{

var str = val.value;

while(str.indexOf(' ')!=-1 && str.indexOf(' ')==0)
{
str = str.substr(1);

}

while(str.lastIndexOf(' ')!=(str.length-1) && str.lastIndexOf(' ')==str.length-1)
{
str = str.substr(0,str.length-1);
}
val.value=str;
}

function isnumber(num1)
{


var re = /^[0-9-'.']*$/;


if (!re.test(num.value))
{
alert("Value must be all numberic charcters, non numeric's removed from field!");
num.value = num.value.replace (/[^0-9-'.']/g,"");
}
if( num.value<0)
{ alert("Value must be greater than 0 ");
forms1.num1.focus();
}
<!--fields.value = fields.value.replace(fields.value,toFixed( fields.value,2));-->
<!--form1.num=RoundToNdp (num,2);-->


}

function countAll(val)
{
trim(val);

var isNumber = isNaN(val.value) ? 0 : 1;

if(val.value.length<=0) isNumber=0;

var num=val.name.substr(8);
var hval=document.getElementById('hid'+num).value;

if(isNumber == 1 && val.value!=hval)
{
forms1.tot.value=parseInt(forms1.tot.value )+parseInt(val.value);
document.getElementById('hid'+num).value=val.value ;
if(hval!='') forms1.tot.value-=parseInt (hval);

}
else
{
if(hval!='' && val.value!=parseInt(hval))
{
forms1.tot.value=parseInt(forms1.tot.value )-parseInt(hval);
document.getElementById ('hid'+num).value=0;
if(isNaN(val.value)) alert("Please Enter value");
val.focus();
}
else
{
if(hval!=val.value)
{
alert("Please Enter value");
val.focus ();
}
else
document.getElementById('del').focus();
}

}

}


function removeEvent(divNum)
{
var d = document.getElementById('myDiv');
var olddiv = document.getElementById(divNum);

var DivLoc = divNum.search(/Div/i);
var num = divNum.substring(2,DivLoc);

var txtCtrl = 'quantity'+num;
var val = document.getElementById(txtCtrl);

if(val.value.length>0)
forms1.tot.value=parseInt(forms1.tot.value)-parseInt(val.value);
//alert(d);

d.removeChild(olddiv);
}

//-->
</script>
</head>

<body>
<form name="forms1">
<input type="hidden" value="0" id="theValue" />
<p><input type="button" value="add some elements" onclick="addEvent();"></p>
<p>Total:<input type="label" readonly value="0" name="tot"></p>
<div id="myDiv"> </div>
</form>
</body>
</html>


the above is the code. the number of the lables should be sequential, instead the number of the deleted row is missing.
Reply