J
Jerry J
Hello,
I am using asp.net 2003 using C#. I am creating textboxes dynamically and
want to validate to make sure the user can only input an integer. I don't
think I can use the validators because I don't know what the ID of the
textbox is ahead of time.
I am trying to do it with javascript with a tableCell.Attributes.Add. I'm
not sure I can do what I am trying.
Here is a pseudo code example of what I am attempting:
TableCell td = new TableCell();
TextBox txtSO = new TextBox();
td.Attributes.Add("onclick","ValidateIntOnly(" + txtSO.text + " );");
td.Controls.Add(txtSO);
tr.Cells.Add(td);
In the html section of the aspx page I have:
<script type ="text/javascript" language="javascript" >
function ValidateIntOnly(i)
{
if(i.value.length>0)
{
i.value = i.value.replace(/[^\d]+/g, '');
}
}
</script>
Can someone help me out with this or tell me a better way to do it?
I am using asp.net 2003 using C#. I am creating textboxes dynamically and
want to validate to make sure the user can only input an integer. I don't
think I can use the validators because I don't know what the ID of the
textbox is ahead of time.
I am trying to do it with javascript with a tableCell.Attributes.Add. I'm
not sure I can do what I am trying.
Here is a pseudo code example of what I am attempting:
TableCell td = new TableCell();
TextBox txtSO = new TextBox();
td.Attributes.Add("onclick","ValidateIntOnly(" + txtSO.text + " );");
td.Controls.Add(txtSO);
tr.Cells.Add(td);
In the html section of the aspx page I have:
<script type ="text/javascript" language="javascript" >
function ValidateIntOnly(i)
{
if(i.value.length>0)
{
i.value = i.value.replace(/[^\d]+/g, '');
}
}
</script>
Can someone help me out with this or tell me a better way to do it?