Newbie JavaScript Help
-
Hi, I am trying to write a script that will take an input field value from a ASP.NET form and determine if its magnetic data from a magstrip on a credit card. The application is written in C# and uses Server Validation controls to validate the data. The controls need to run server side because when the SUBMIT button is pushed the server needs to validate the data. I do not want to send the data when the Credit Card Number field looses focus to the server, it is disruptive to the user but I need to determine if the card was swipped and if so pull off the Card Number, Card Holder's Name and the Expiration Date and populate the fields. Since I'm new to JavaScript, I figured I would write something simple and hook it to my code for OnTextChange. The problem is I'm receiving the following error: Compiler Error Message: CS0117: 'ASP.WebForm1_aspx' does not contain a definition for 'isScanned' I put my JavaScript in the head section as follows:
Merchant Charge Plus / 2004 Web - Authorization Screen function isScanned( ) { var index = 0; CardNo = document.Form1.efCardNo.value; if (CardNo.subString(0, 2) == "%b" || CardNo.subString(0, 2) == "%B" || CardNo.subString(0, 2) == "%a" || CardNo.subString(0, 2) == "%A") { window.alert("Card was scanned"); } return; }
and the call for the routine is:asp:TextBox id="efCardNo" style="Z-INDEX: 112; LEFT: 152px; POSITION: absolute; TOP: 67px" tabIndex="3" OnTextChanged="isScanned" runat="server" ToolTip="Enter the Card Holder's name as it appears on the card" Width="193"
I don't see what I did wrong, I see the function. Is it because of the runat="server" and it thinks the function is on the server? If so, how do I have a client side routine and a server side? Thanks for your help, Glenn -
Hi, I am trying to write a script that will take an input field value from a ASP.NET form and determine if its magnetic data from a magstrip on a credit card. The application is written in C# and uses Server Validation controls to validate the data. The controls need to run server side because when the SUBMIT button is pushed the server needs to validate the data. I do not want to send the data when the Credit Card Number field looses focus to the server, it is disruptive to the user but I need to determine if the card was swipped and if so pull off the Card Number, Card Holder's Name and the Expiration Date and populate the fields. Since I'm new to JavaScript, I figured I would write something simple and hook it to my code for OnTextChange. The problem is I'm receiving the following error: Compiler Error Message: CS0117: 'ASP.WebForm1_aspx' does not contain a definition for 'isScanned' I put my JavaScript in the head section as follows:
Merchant Charge Plus / 2004 Web - Authorization Screen function isScanned( ) { var index = 0; CardNo = document.Form1.efCardNo.value; if (CardNo.subString(0, 2) == "%b" || CardNo.subString(0, 2) == "%B" || CardNo.subString(0, 2) == "%a" || CardNo.subString(0, 2) == "%A") { window.alert("Card was scanned"); } return; }
and the call for the routine is:asp:TextBox id="efCardNo" style="Z-INDEX: 112; LEFT: 152px; POSITION: absolute; TOP: 67px" tabIndex="3" OnTextChanged="isScanned" runat="server" ToolTip="Enter the Card Holder's name as it appears on the card" Width="193"
I don't see what I did wrong, I see the function. Is it because of the runat="server" and it thinks the function is on the server? If so, how do I have a client side routine and a server side? Thanks for your help, GlennOnTextChanged is the server side event, where as you have written the a client side event handler. Try adding the attribute onchange="isScanned();" which should be the client side event for a text field.