Menu
Hi,
I found a script for testing numeric values in a textbox, as follows:
function IsNumeric(test)
{
if (test==””) {
return false
alert(“test==”)
}
for (i=0; i<test.length; i++)
{
if (test.charAt(i) <“0”) {
return false
alert(“<0”)
}
if (test.charAt(i) >”9″) {
return false
alert(“>9”)
}
}
}
Script doesnot work. What is wrong ?
regards, Ger.
[code=php]function IsNumeric(input)
{
if (input == '' || isNaN(input)){
alert('is not numeric');
return false;
}
return true;
}[/code]
<i>
</i>function IsNumeric(test)
{
if (test=="") {
return false; //Semi colon (;)
alert("test=="); //Semi colon (;)
}
for (i=0; i<test.length; i++)
{
if (test.charAt(i) <"0") {
return false; //Semi colon (;)
alert("<0"); //Semi colon (;)
}
if (test.charAt(i) >"9") {
return false; //Semi colon (;)
alert(">9"); //Semi colon (;)
}
}
return true; //You hadn't told it to return true!
}
<i>
</i> function IsNumeric(test)
{
if (test=="") {
[color=blue]alert("test==")
return false[/color]
}
for (i=0; i<test.length; i++)
{
if (test.charAt(i) <"0") {
[color=blue]alert("<0")
return false[/color]
}
if (test.charAt(i) >"9") {
[color=blue]alert(">9")
return false[/color]
}
}
}
[code=php]function IsNumeric(input)
{
if (input == '') return false;
point = '0';
for(i = 0; i < input.length; i++){
character = input[i];
if(isNaN(character) && (character == ',' || character == '.' )){
point++;
}else{
if(isNaN(character)){
return false;
}
}
}
if(point > 1) return false;
return true;
}[/code]
[code=php]if(IsNumeric(input.fieldname.value)){
alert(input.fieldname + ' is not correctly filled in');
return false;
}[/code]
where [B]input.fieldname.value[/B] relates to your form.[code=php]form = document.getElementById('form');
if(!IsNumeric(form.fieldname.value)){
form.fieldname.value = '0.00';
Recalculate();
}[/code]
I can't help further without seeing the code (posted between code tags).[code=php]function check_me(input){
if(!IsNumeric(document.getElementById(input).value){
document.getElementById(input).value = '0.00';
}
Recalculate();
}[/code]
[code=php]
<INPUT id="txtInk1" onchange="check_me(this.id)" style="xxxx" type="text" value="0.00" name="txtInk1" runat="server">[/code]
[code=php][/code]
tags so it is readable. <script type="text/javascript">
function Bereken()
{
a = parseFloat(document.Form1.txtInk1.value)
document.Form1.txtInk1.value = a.toFixed (2)
b = parseFloat(document.Form1.txtInk2.value)
document.Form1.txtInk2.value = b.toFixed (2)
c = parseFloat(document.Form1.txtInk3.value)
document.Form1.txtInk3.value = c.toFixed (2)
d = parseFloat(document.Form1.txtInk4.value)
document.Form1.txtInk4.value = d.toFixed (2)
tot = (a+b+c+d)
document.Form1.txtInkTot.value = tot.toFixed (2)
a = parseFloat(document.Form1.txtVerk1.value)
document.Form1.txtVerk1.value = a.toFixed (2)
b = parseFloat(document.Form1.txtVerk2.value)
document.Form1.txtVerk2.value = b.toFixed (2)
c = parseFloat(document.Form1.txtVerk3.value)
document.Form1.txtVerk3.value = c.toFixed (2)
d = parseFloat(document.Form1.txtVerk4.value)
document.Form1.txtVerk4.value = d.toFixed (2)
tot = (a+b+c+d)
document.Form1.txtVerkTot.value = tot.toFixed (2)
a = parseFloat(document.Form1.txtVerk1.value)
b = parseFloat(document.Form1.txtInk1.value)
tot = (a-b)
document.Form1.txtVers1.value = tot.toFixed (2)
a = parseFloat(document.Form1.txtVerk2.value)
b = parseFloat(document.Form1.txtInk2.value)
tot = (a-b)
document.Form1.txtVers2.value = tot.toFixed (2)
a = parseFloat(document.Form1.txtVerk3.value)
b = parseFloat(document.Form1.txtInk3.value)
tot = (a-b)
document.Form1.txtVers3.value = tot.toFixed (2)
a = parseFloat(document.Form1.txtVerk4.value)
b = parseFloat(document.Form1.txtInk4.value)
tot = (a-b)
document.Form1.txtVers4.value = tot.toFixed (2)
a = parseFloat(document.Form1.txtVerkTot.value)
b = parseFloat(document.Form1.txtInkTot.value)
tot = (a-b)
document.Form1.txtVersTot.value = tot.toFixed (2)
}
function IsNumeric(input)
{
if (input == '') return false;
point = '0';
for(i = 0; i < input.length; i++){
character = input[i];
if(character == ',' || character == '.' ){
point++;
}else{
if(isNaN(character)){
return false;
}
}
}
if(point > 1) return false;
return true;
}
function CheckNum(input){
if (!IsNumeric(document.getElementById(input).value)){
document.getElementById(input).value = "0.00"
alert("Alleen cijfers toegestaan");
//input.focus(); //(wordt niet ondersteund ?)
}
Bereken()
}
</script>
<form id="Form1" method="post" runat="server">
<asp:panel id="PanelTWV" style="Z-INDEX: 101; LEFT: 232px; POSITION: absolute; TOP: 208px"
runat="server" Height="146px" Width="200px" BackColor="#F9FFFF" BorderColor="#1E3C7B" BorderWidth="1px"
BorderStyle="Solid">
<P><FONT face="Verdana" size="2"><STRONG> Projecten</STRONG></FONT></P>
<P><FONT face="Verdana" size="2">
<TABLE id="Tablefuncties" style="WIDTH: 190px; HEIGHT: 75px" borderColor="#1e3c7b" cellSpacing="0"
cellPadding="10" width="190" border="0">
<TR>
<TD style="WIDTH: 66px"></TD>
<TD>
<asp:LinkButton id="lnkToevoegen" runat="server" Font-Size="X-Small" Font-Names="Verdana" Font-Bold="True">Toevoegen</asp:LinkButton></TD>
</TR>
<TR>
<TD style="WIDTH: 66px"></TD>
<TD>
<asp:LinkButton id="lnkWijzigen" runat="server" Font-Size="X-Small" Font-Names="Verdana" Font-Bold="True">Wijzigen</asp:LinkButton></TD>
</TR>
<TR>
<TD style="WIDTH: 66px"></TD>
<TD>
<asp:LinkButton id="lnkVerwijderen" runat="server" Font-Size="X-Small" Font-Names="Verdana" Font-Bold="True">Verwijderen</asp:LinkButton></TD>
</TR>
</TABLE>
</FONT></TR></TBODY></TABLE></P>
</asp:panel><asp:panel id="PanelOnderhoud" style="Z-INDEX: 103; LEFT: 536px; POSITION: absolute; TOP: 208px"
runat="server" Height="400px" Width="400px" BackColor="#F9FFFF" BorderColor="#1E3C7B" BorderWidth="1px"
BorderStyle="Solid" Visible="False">
<P><BR>
<TABLE id="Table_Onderhoud" cellSpacing="1" cellPadding="1" width="100%" border="0">
<TR>
<TD style="WIDTH: 145px"><FONT face="Verdana" size="2"><STRONG>Projectnummer :</STRONG></FONT></TD>
<TD>
<asp:TextBox id="txtProjectnr" runat="server" Width="198px" Font-Size="X-Small" Font-Names="Verdana"
MaxLength="8" ToolTip="Vul hier het projectnr. in volgens het sjabloon: jaar-volgnr."></asp:TextBox></TD>
</TR>
<TR>
<TD style="WIDTH: 145px"><FONT face="Verdana" size="2"><STRONG>Projectomschrijving :</STRONG></FONT></TD>
<TD>
<asp:TextBox id="txtProjectomschrijving" runat="server" Width="198px" Font-Size="X-Small" Font-Names="Verdana"
MaxLength="30" ToolTip="Vul hier de projectomschrijving in."></asp:TextBox></TD>
</TR>
<TR>
<TD style="WIDTH: 145px; HEIGHT: 17px"><FONT face="Verdana" size="2"><STRONG>Opdrachtgever
:</STRONG></FONT></TD>
<TD style="HEIGHT: 17px">
<P>
<asp:DropDownList id=DDL_OG runat="server" Width="176px" Font-Size="X-Small" Font-Names="Verdana" Visible="False" DataSource="<%# DsOG %>" DataTextField="Naam" DataValueField="OpdrachtgeverID" DataMember="Opdrachtgevers">
</asp:DropDownList></P>
</TD>
</TR>
<TR>
<TD style="WIDTH: 145px; HEIGHT: 1px"><FONT face="Verdana" size="2"><STRONG>Contactpersoon
:</STRONG></FONT></TD>
<TD style="HEIGHT: 1px">
<asp:DropDownList id=DDL_CP runat="server" Width="176px" Font-Size="X-Small" Font-Names="Verdana" Visible="False" DataSource="<%# DsCP %>" DataTextField="Naam" DataValueField="ContactpersoonID" DataMember="Contactpersonen">
</asp:DropDownList></TD>
</TR>
<TR>
<TD style="WIDTH: 145px"></TD>
<TD></TD>
</TR>
<TR>
<TD style="WIDTH: 145px"></TD>
<TD></TD>
</TR>
<TR>
<TD style="WIDTH: 145px"></TD>
<TD>
<P>
<asp:Button id="btnOpslaan" runat="server" BackColor="#1E3C7B" Font-Size="X-Small" Font-Names="Verdana"
Font-Bold="True" ForeColor="White" Text="Verwijderen"></asp:Button></P>
</TD>
</TR>
</TABLE>
</P>
<TABLE id="TableInkVerk" style="FONT-WEIGHT: bold; FONT-SIZE: x-small; BACKGROUND-IMAGE: none; WIDTH: 395px; COLOR: red; FONT-FAMILY: Verdana; HEIGHT: 188px; BACKGROUND-COLOR: lemonchiffon"
cellSpacing="1" cellPadding="1" width="400" align="center" borderColorLight="#000099"
border="1">
<TR style="HEIGHT: 10px">
<TD style="VERTICAL-ALIGN: baseline; WIDTH: 173px; LINE-HEIGHT: normal; LETTER-SPACING: normal; POSITION: static; HEIGHT: 10px; TEXT-ALIGN: center"><FONT color="#000099">Opdrachtnemer</FONT></TD>
<TD style="VERTICAL-ALIGN: baseline; WIDTH: 114px; LINE-HEIGHT: normal; LETTER-SPACING: normal; POSITION: static; HEIGHT: 10px; TEXT-ALIGN: center"><FONT color="#000099">Inkoop</FONT></TD>
<TD style="VERTICAL-ALIGN: baseline; WIDTH: 173px; LINE-HEIGHT: normal; LETTER-SPACING: normal; POSITION: static; HEIGHT: 10px; TEXT-ALIGN: center"><FONT color="#000099">Verkoop</FONT></TD>
<TD style="VERTICAL-ALIGN: baseline; WIDTH: 173px; LINE-HEIGHT: normal; LETTER-SPACING: normal; POSITION: static; HEIGHT: 10px; TEXT-ALIGN: center"><FONT color="#000099">Verschil</FONT></TD>
</TR>
<TR>
<TD style="WIDTH: 143px; HEIGHT: 16px">
<asp:DropDownList id="DDL_IV1" runat="server" Width="122px" AutoPostBack="True"></asp:DropDownList></TD>
<TD style="WIDTH: 114px; HEIGHT: 16px">
[COLOR=Red]<INPUT id="txtInk1" style="WIDTH: 80px; HEIGHT: 22px; TEXT-ALIGN: right"
type="text" maxLength="8" onchange="Bereken()" align="right" size="9" onblur="CheckNum(this.id)" value="0.00" name="txtInk1" runat="server"></TD>[/COLOR] <TD style="WIDTH: 143px; HEIGHT: 16px"><INPUT id="txtVerk1" onblur="CheckNum(this.id)" style="WIDTH: 80px; HEIGHT: 22px; TEXT-ALIGN: right"
type="text" maxLength="8" onchange="Bereken()" align="right" size="9" value="0.00" name="txtVerk1" runat="server"></TD>
<TD><INPUT id="txtVers1" style="WIDTH: 80px; HEIGHT: 22px; TEXT-ALIGN: right" readOnly type="text"
align="right" size="9" value="0.00"></TD>
</TR>
0.1.9 — BETA 5.4