Sign In| Join
Get Help:Ask a Question in our Forums|Report a Bug|More Help Resources
Last post Apr 15, 2012 05:13 PM by Muhammad Fakhr Elden Sami
Member
94 Points
149 Posts
Apr 15, 2012 04:41 PM|LINK
Hi,
I have one form that uses Javascript to validate some textbox fields.
I would like that this textbox fields can only accept number from 0 to 9 and , and . how can I achive this?
Thank you very much.
Here is the code of my form:
<%
@ Page Title="" Language="vb" AutoEventWireup="false" MasterPageFile="~/Site.Master" CodeBehind="Facturas.aspx.vb" Inherits="WebRole1.Facturas"
%>
@ Register TagPrefix="asp" Namespace="AjaxControlToolkit" Assembly="AjaxControlToolkit"
<
asp:Content ID="Content1" ContentPlaceHolderID="HeadContent" runat
="server">
<style type
="text/css">
.style1
{
width: 224px
;
}
.style5
width: 258px
.style6
width: 76px
.style7
width: 48px
.style8
width: 62px
</style
>
</
asp:Content
asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat
<table style="width:600px; height:0px;">
<tr
<td align =
"right">
</td
</tr
</table
<table style="width:600px; height:40px; border:2px" >
<td class
="style1">
<asp:Label ID="Label1" runat="server" Text="Data Sistema :" ToolTip
="Referência"
Font-Overline="False" Font-Size="14px"></asp:Label
<asp:TextBox ID="txtDataSistema" runat="server" MaxLength="50" Width="134px" BackColor="LightYellow"></asp:TextBox
="style6">
<td class="style5">
<asp:Label ID="Label3" runat="server" Text="Data Factura :" ToolTip=""
<asp:TextBox ID="TxtDataFactura" runat="server" MaxLength="50" Width="135px"
style="margin-left: 1px"></asp:TextBox
<td style ="width:225px">
<asp:Label ID="Label7" runat="server" Text="Número Factura :" ToolTip=""
<asp:TextBox ID="TxtNumeroFactura" runat="server" MaxLength="50" Width="187px"></asp:TextBox
="style8">
<asp:Label ID="Label2" runat="server" Text="Estado :" ToolTip="Estado da Factura"
<asp:DropDownList ID="DropDownEstado" runat="server" Width="141px"
AppendDataBoundItems ="true" Height
="22px">
<asp:ListItem Text="Seleccione" Value=""
/>
</asp:DropDownList
="style7">
="style5">
<asp:Label ID="Label4" runat="server" Text="Fornecedor :" ToolTip="Estado da Factura"
<asp:DropDownList ID="DropDownForn" runat="server" Width="378px"
AppendDataBoundItems ="true" Height="21px" style="margin-left
: 3px">
<table style="height
:10px;">
<asp:ToolkitScriptManager ID="ToolkitScriptManager1" runat="Server"
<table style="width:600px; height:151px; margin-top:0px;">
<tr align
="left">
"left">
<ajaxToolkit:TabContainer ID="TabContainer1" runat="server" Height="135px" Width
="587px"
style="margin-left: 0px; margin-top: 0px; border-width:medium; " ActiveTabIndex
="1"
AutoPostBack
="True">
<ajaxToolkit:TabPanel runat="server" HeaderText="Produtos" ID="Produtos" ForeColor
="#CC0000">
<ContentTemplate
<asp:GridView ID="GridView1" runat="server" Height="20px" Width
="570px"
style="margin-left: 0px" PageSize
="4">
<Columns
<asp:TemplateField HeaderText
="Alterar">
<EditItemTemplate
<asp:CheckBox ID="CheckBox1" runat="server"
</EditItemTemplate
<ItemTemplate
</ItemTemplate
</asp:TemplateField
="Eliminar">
<asp:CheckBox ID="CheckBox2" runat="server"
</Columns
</asp:GridView
</ContentTemplate
</ajaxToolkit:TabPanel>
<ajaxToolkit:TabPanel ID="Adicionar" runat="server" HeaderText
="Adicionar Produtos">
ContentTemplate
<p
<table
<td
<asp:Button ID="Button1" runat="server" Text="Produto" Width="67px" Height="22px"
BackColor="#CC0000" ForeColor
="White"/>
<asp:TextBox ID="TextBox1" runat="server" Width="100px" style="margin-left: 21px" Height="16px" BackColor="LightYellow" ></asp:TextBox
<asp:TextBox ID="TextBox2" runat="server" Width="305px" Height="16px" BackColor="LightYellow" ></asp:TextBox
:10px">
<td style="WIDTH
: 92PX;">
<asp:TextBox ID="Quantidade" runat="server" Width="65px" Height="16px" onblur='getbackdata(this)' onfocus='emptytextbox(this)' ></asp:TextBox
<asp:TextBox ID="ValorUni" runat="server" Height="16px" Width="90px" onblur='getbackdata(this)' onfocus='emptytextbox(this)' ></asp:TextBox
<asp:TextBox ID="Iva" runat="server" Width="65px" Height="16px" onblur='getbackdata(this)' onfocus='emptytextbox(this)' ></asp:TextBox
<asp:TextBox ID="Desc" runat="server" Width="65px" Height="16px" onblur='getbackdata(this)' onfocus='emptytextbox(this)' ></asp:TextBox
<asp:TextBox ID="STotal" runat="server" Width="90px" Height="16px" BackColor="LightYellow" Text="" ></asp:TextBox
</p
<table style="height:10px; width
:570px">
="right">
"center">
<asp:Button ID="Button2" runat="server" Text="Ok" BackColor="#CC0000"
ForeColor="White" Height="22px" Width="38px"
</TD
</ajaxToolkit:TabPanel
</ajaxToolkit:TabContainer
<table style="width:595px; ">
<td align
<asp:TextBox ID="TextBox3" runat="server" MaxLength="50" Width="134px" text ="Total: 0" BackColor
="LightYellow"
Height="18px" ></asp:TextBox
<asp:Button ID="txtcmdCancelar" runat="server" Text="Cancelar" BackColor="#CC0000"
ForeColor="White" Height="22px" Width="92px"
<asp:Button ID="txtCmdConfirmar" runat="server" Text="Confirmar" BackColor="#CC0000"
script type
="text/javascript">
var
defaulttext;
function
getbackdata(id) {
if (id.value == ""
) {
id.value = defaulttext;
emptytextbox(id) {
defaulttext = id.value;
id.value =
""
</script
Contributor
2268 Points
511 Posts
Apr 15, 2012 05:13 PM|LINK
Dear friend,
you can accomplish what you want using asp.net range validator control
http://msdn.microsoft.com/en-us/library/f70d09xt(v=vs.71).aspx
PedroRibeiro
Member
94 Points
149 Posts
Java script function
Apr 15, 2012 04:41 PM|LINK
Hi,
I have one form that uses Javascript to validate some textbox fields.
I would like that this textbox fields can only accept number from 0 to 9 and , and . how can I achive this?
Thank you very much.
Here is the code of my form:
<%
@ Page Title="" Language="vb" AutoEventWireup="false" MasterPageFile="~/Site.Master" CodeBehind="Facturas.aspx.vb" Inherits="WebRole1.Facturas"
%>
<%
@ Register TagPrefix="asp" Namespace="AjaxControlToolkit" Assembly="AjaxControlToolkit"
%>
<
asp:Content ID="Content1" ContentPlaceHolderID="HeadContent" runat
="server">
<style type
="text/css">
.style1
{
width: 224px
;
}
.style5
{
width: 258px
;
}
.style6
{
width: 76px
;
}
.style7
{
width: 48px
;
}
.style8
{
width: 62px
;
}
</style
>
</
asp:Content
>
<
asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat
="server">
<table style="width:600px; height:0px;">
<tr
>
<td align =
"right">
</td
>
</tr
>
</table
>
<table style="width:600px; height:40px; border:2px" >
<tr
>
<td class
="style1">
<asp:Label ID="Label1" runat="server" Text="Data Sistema :" ToolTip
="Referência"
Font-Overline="False" Font-Size="14px"></asp:Label
>
<asp:TextBox ID="txtDataSistema" runat="server" MaxLength="50" Width="134px" BackColor="LightYellow"></asp:TextBox
>
</td
>
<td class
="style6">
</td
>
<td class="style5">
<asp:Label ID="Label3" runat="server" Text="Data Factura :" ToolTip=""
Font-Overline="False" Font-Size="14px"></asp:Label
>
<asp:TextBox ID="TxtDataFactura" runat="server" MaxLength="50" Width="135px"
style="margin-left: 1px"></asp:TextBox
>
</td
>
<td style ="width:225px">
<asp:Label ID="Label7" runat="server" Text="Número Factura :" ToolTip=""
Font-Overline="False" Font-Size="14px"></asp:Label
>
<asp:TextBox ID="TxtNumeroFactura" runat="server" MaxLength="50" Width="187px"></asp:TextBox
>
</td
>
</tr
>
</table
>
<table style="width:600px; height:40px; border:2px" >
<tr
>
<td class
="style8">
<asp:Label ID="Label2" runat="server" Text="Estado :" ToolTip="Estado da Factura"
Font-Overline="False" Font-Size="14px"></asp:Label
>
<asp:DropDownList ID="DropDownEstado" runat="server" Width="141px"
AppendDataBoundItems ="true" Height
="22px">
<asp:ListItem Text="Seleccione" Value=""
/>
</asp:DropDownList
>
</td
>
<td class
="style7">
</td
>
<td class
="style5">
<asp:Label ID="Label4" runat="server" Text="Fornecedor :" ToolTip="Estado da Factura"
Font-Overline="False" Font-Size="14px"></asp:Label
>
<asp:DropDownList ID="DropDownForn" runat="server" Width="378px"
AppendDataBoundItems ="true" Height="21px" style="margin-left
: 3px">
<asp:ListItem Text="Seleccione" Value=""
/>
</asp:DropDownList
>
</td
>
</tr
>
</table
>
<table style="height
:10px;">
</table
>
<asp:ToolkitScriptManager ID="ToolkitScriptManager1" runat="Server"
/>
<table style="width:600px; height:151px; margin-top:0px;">
<tr align
="left">
<td align =
"left">
<ajaxToolkit:TabContainer ID="TabContainer1" runat="server" Height="135px" Width
="587px"
style="margin-left: 0px; margin-top: 0px; border-width:medium; " ActiveTabIndex
="1"
AutoPostBack
="True">
<ajaxToolkit:TabPanel runat="server" HeaderText="Produtos" ID="Produtos" ForeColor
="#CC0000">
<ContentTemplate
>
<asp:GridView ID="GridView1" runat="server" Height="20px" Width
="570px"
style="margin-left: 0px" PageSize
="4">
<Columns
>
<asp:TemplateField HeaderText
="Alterar">
<EditItemTemplate
>
<asp:CheckBox ID="CheckBox1" runat="server"
/>
</EditItemTemplate
>
<ItemTemplate
>
<asp:CheckBox ID="CheckBox1" runat="server"
/>
</ItemTemplate
>
</asp:TemplateField
>
<asp:TemplateField HeaderText
="Eliminar">
<EditItemTemplate
>
<asp:CheckBox ID="CheckBox2" runat="server"
/>
</EditItemTemplate
>
<ItemTemplate
>
<asp:CheckBox ID="CheckBox2" runat="server"
/>
</ItemTemplate
>
</asp:TemplateField
>
</Columns
>
</asp:GridView
>
</ContentTemplate
>
</ajaxToolkit:TabPanel>
<ajaxToolkit:TabPanel ID="Adicionar" runat="server" HeaderText
="Adicionar Produtos">
<
ContentTemplate
>
<p
>
<p
>
<table
>
<tr
>
<td
>
<asp:Button ID="Button1" runat="server" Text="Produto" Width="67px" Height="22px"
BackColor="#CC0000" ForeColor
="White"/>
</td
>
<td
>
</td
>
<td
>
<asp:TextBox ID="TextBox1" runat="server" Width="100px" style="margin-left: 21px" Height="16px" BackColor="LightYellow" ></asp:TextBox
>
</td
>
<td
>
<asp:TextBox ID="TextBox2" runat="server" Width="305px" Height="16px" BackColor="LightYellow" ></asp:TextBox
>
</td
>
</tr
>
</table
>
<table style="height
:10px">
</table
>
<table
>
<tr
>
<td style="WIDTH
: 92PX;">
</td
>
<td
>
<asp:TextBox ID="Quantidade" runat="server" Width="65px" Height="16px" onblur='getbackdata(this)' onfocus='emptytextbox(this)' ></asp:TextBox
>
</td
>
<td
>
<asp:TextBox ID="ValorUni" runat="server" Height="16px" Width="90px" onblur='getbackdata(this)' onfocus='emptytextbox(this)' ></asp:TextBox
>
</td
>
<td
>
<asp:TextBox ID="Iva" runat="server" Width="65px" Height="16px" onblur='getbackdata(this)' onfocus='emptytextbox(this)' ></asp:TextBox
>
</td
>
<td
>
<asp:TextBox ID="Desc" runat="server" Width="65px" Height="16px" onblur='getbackdata(this)' onfocus='emptytextbox(this)' ></asp:TextBox
>
</td
>
<td
>
<asp:TextBox ID="STotal" runat="server" Width="90px" Height="16px" BackColor="LightYellow" Text="" ></asp:TextBox
>
</td
>
</tr
>
</p
>
</p
>
</table
>
<table style="height
:10px">
</table
>
<table style="height:10px; width
:570px">
<tr align
="right">
<td align =
"center">
<asp:Button ID="Button2" runat="server" Text="Ok" BackColor="#CC0000"
ForeColor="White" Height="22px" Width="38px"
/>
</TD
>
</tr
>
</table
>
</ContentTemplate
>
</ajaxToolkit:TabPanel
>
</ajaxToolkit:TabContainer
>
</td
>
</tr
>
</table
>
<table style="width:595px; ">
<tr
>
<td align
="left">
<asp:TextBox ID="TextBox3" runat="server" MaxLength="50" Width="134px" text ="Total: 0" BackColor
="LightYellow"
Height="18px" ></asp:TextBox
>
</td
>
<td align =
"right">
<asp:Button ID="txtcmdCancelar" runat="server" Text="Cancelar" BackColor="#CC0000"
ForeColor="White" Height="22px" Width="92px"
/>
<asp:Button ID="txtCmdConfirmar" runat="server" Text="Confirmar" BackColor="#CC0000"
ForeColor="White" Height="22px" Width="92px"
/>
</td
>
</tr
>
</table
>
<
script type
="text/javascript">
var
defaulttext;
function
getbackdata(id) {
if (id.value == ""
) {
id.value = defaulttext;
}
}
function
emptytextbox(id) {
defaulttext = id.value;
id.value =
""
;
}
</script
>
</
asp:Content
>
Muhammad Fak...
Contributor
2268 Points
511 Posts
Re: Java script function
Apr 15, 2012 05:13 PM|LINK
Dear friend,
you can accomplish what you want using asp.net range validator control
http://msdn.microsoft.com/en-us/library/f70d09xt(v=vs.71).aspx
If you feel it helps, Mark as answered so that it can help others to find solution.
For Any further questions, please contact me.