By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,521 Members | 1,274 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,521 IT Pros & Developers. It's quick & easy.

Dynamically create text boxes and add numbers

P: 8
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.
Nov 28 '06 #1
Share this Question
Share on Google+
9 Replies


P: 8
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.
Nov 28 '06 #2

P: 3
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?
Nov 28 '06 #3

Expert 100+
P: 1,892
Please don't double post, also be more specific with what kind of help you need
Nov 28 '06 #4

P: 8
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.
Nov 29 '06 #5

P: 8
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.
Nov 29 '06 #6

P: 1
how are you ???????
Nov 29 '06 #7

10K+
P: 13,264
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.
Nov 29 '06 #8

10K+
P: 13,264
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
Nov 29 '06 #9

P: 8
<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.
Dec 1 '06 #10

Post your reply

Sign in to post your reply or Sign up for a free account.