hi
i have a function in javascript and i want to call it in codebehind.i have a server button and i want to call it when i click on.
please help me.
JavaScript Copy
@ Page Language ="VB" AutoEventWireup ="false" CodeFile ="Default.aspx.vb" Inherits ="_Default" %>
DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd" >
html xmlns="http://www.w3.org/1999/xhtml" >
head runat="server" >
title>Untitled Pagetitle >
head>
script language=javascript type="text/javascript" >
function cMC (vmc )
{
var mc;
mc = vmc.value ;
if (mc.length == 10 )
{
if (mc == '1111111111' || mc == '0000000000' || mc == '2222222222' || mc == '3333333333' || mc == '4444444444' || mc == '5555555555' || mc == '6666666666' || mc == '7777777777' || mc == '8888888888' || mc == '9999999999' )
{
alert ('dont right' );
vmc.focus ();
return false ;
}
c = parseInt (mc.charAt (9 ));
n = parseInt (mc.charAt (0 )) * 10 +parseInt (mc.charAt (1 )) * 9 +parseInt (mc.charAt (2 )) * 8 +parseInt (mc.charAt (3 )) * 7 +parseInt (mc.charAt (4 )) * 6 + parseInt (mc.charAt (5 )) * 5 +parseInt (mc.charAt (6 )) * 4 +parseInt (mc.charAt (7 )) * 3 + parseInt (mc.charAt (8 )) * 2 ;
r = n - parseInt (n / 11 ) * 11 ;
if ((r == 0 && r == c) || (r == 1 && c == 1 ) || (r > 1 && c == 11 - r))
{
return true ;
}
else
{
alert ('dont right' );
vmc.focus ();
return false ;
}
}
else {
alert ('please insert 10 figure' );
vmc.focus ();
return false ;
}
}
script>
form id="form1" runat="server" >
body>
div>
asp :TextBox ID ="TextBox1" runat="server" >asp :TextBox >
asp :Button ID ="Button1" runat="server" Text ="Button" onclick=" cMC(document.getElementById(''))" Height ="26px" />
div>
form>
body>
html>
Jaish MathewsRank #225 · 11K reputationPosted Sep 5, 2010, 10:15 AM EDT
HTML and JS
function cMC() {
var textBoxID = document.getElementById("textFieldValue").value;
var textBoxValue = document.getElementById(textBoxID).value;
alert(textBoxValue);
}
<asp:TextBox ID="TextBox1" runat="server">asp:TextBox>
<asp:Button ID="Button1" runat="server" Text="Button" OnClientClick="cMC()" />
form>
C#
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
ScriptManager.RegisterHiddenField(this, "textFieldValue", TextBox1.ClientID);
}
}