473,324 Members | 2,548 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,324 software developers and data experts.

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.
Nov 28 '06 #1
9 4021
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
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
AricC
1,892 Expert 1GB
Please don't double post, also be more specific with what kind of help you need
Nov 28 '06 #4
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
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
liat
1
how are you ???????
Nov 29 '06 #7
r035198x
13,262 8TB
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
r035198x
13,262 8TB
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
<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

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

Similar topics

0
by: LU | last post by:
I have code to dynamically add more text boxes when the user clicks the 'add another carrier' button. Problem is it creates the text boxes within the same table row as previously created boxes. ...
4
by: Chris Sharman | last post by:
I've got 3 'alternative' boxes, only one of which I want displayed, according to the value of an earlier select (so I'm using the <htmlelement>.style property from javascript). One is a div...
7
by: juglesh | last post by:
Hello, I would like to be able to have the user sort a list of items similarly to the way you sort your queue on Netflix.com. (the numbers dont change dynamically on netflix, they must be doing...
8
by: Donald Xie | last post by:
Hi, I noticed an interesting effect when working with controls that are dynamically loaded. For instance, on a web form with a PlaceHolder control named ImageHolder, I dynamically add an image...
2
by: jmarendo | last post by:
Hello, After reading through the "Table Basics - DOM - Refer to table cells" example at mredkj.com , I modified the code for my own purposes. In the modified version, I create a hyperlink and...
12
by: vbnewbie | last post by:
I am having problems accessing properties of dynamically generated objects in VB2005. Can someone please help? In a nutshell: My app creates an equal number of checkboxes and labels that share the...
6
by: Bjorn Sagbakken | last post by:
Hello In VS2005: I am adding buttons and textboxes dynamically into a table, that also dynamically expands. So far, so good, actually very nice. But I am having trouble starting the desired...
1
by: =?Utf-8?B?bWFya203NQ==?= | last post by:
I have a simple page i'm trying to do dynmaically.. i have a page called submitcomments.aspx with the .cs codebehind.. before i created everything in design view.. now i've ripped that out and...
1
by: adarshyam | last post by:
can anybody tel me how to clear values from dynamically created text boxes?? using a clear button.. this is the code used to create dynamic text boxes.. if i press clear button then it must clear all...
2
by: gubbachchi | last post by:
Hi, I have a form whose elements are created dynamically on selection, i.e. the form has only text boxes and the number of text boxes depends on the users selection, if user selects 3 then 3...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.