Hi I am trying to pass parameter to the Javascript function from code behind as follows: in Page_Load i have btnAddSymChange.Attributes.Add("onClick", "return ValidateText(" + txtChValue.Text + ")") in aspx page i have <script language="javascript"> function
ValidateText(ChValue) { //If(i=="") //{ alert(ChValue); return false; //} } </script> I get an alert as undefined.. what is the problem here? Thanx jkj
Thanx for the reply... It works now but i have another prb here I have the code as follwos: <script language="javascript"> // whitespace characters var whitespace = " \t\n\r"; /****************************************************************/ // Check whether
string s is empty. function isEmpty(s) { return ((s == null) || (s.length == 0)) } /****************************************************************/ function isWhitespace (s) { var i; // Is s empty? if (isEmpty(s)) return true; // Search through string's
characters one by one // until we find a non-whitespace character. // When we do, return false; if we don't, return true. for (i = 0; i < s.length; i++) { // Check that current character isn't whitespace. var c = s.charAt(i); if (whitespace.indexOf(c) == -1)
return false; } // All characters are whitespace. return true; } /****************************************************************/ function ValidateSymChange(symChangeValue) { var strInput = new String(symChangeValue); If(isWhitespace(strInput)) { alert("test");
return false; } } </script> n the code is as follows in the code behind file: btnAddSymChange.Attributes.Add("onClick", "return ValidateSymChange(document.all.txtSymbolChange.value)") But JS function returns a true ...and the error it shows is Object recquired
what is thr prb here? thanx jkj.
Hi Thanx for the reply... But I get a different problem now... I have the following code in the aspx page: <script language="javascript"> // whitespace characters var whitespace = " \t\n\r"; /****************************************************************/
// Check whether string s is empty. function isEmpty(s) { return ((s == null) || (s.length == 0)) } /****************************************************************/ function isWhitespace (s) { var i; // Is s empty? if (isEmpty(s)) return true; // Search
through string's characters one by one // until we find a non-whitespace character. // When we do, return false; if we don't, return true. for (i = 0; i < s.length; i++) { // Check that current character isn't whitespace. var c = s.charAt(i); if (whitespace.indexOf(c)
== -1) return false; } // All characters are whitespace. return true; } /****************************************************************/ function ValidateSymChange(symChangeValue) { var strInput = new String(symChangeValue); If(isWhitespace(strInput)) {
alert("test"); return false; } } </script> and I call the function from the code behind as follows: btnAddSymChange.Attributes.Add("onClick", "return ValidateSymChange(document.all.txtSymbolChange.value)") But i get a return value as true...when the textbox
is empty the JS error reads: Object Expected at this line: var strInput = new String(symChangeValue); what could be the cause for the error.. Thanx Jkj
jkj1998
Member
15 Points
3 Posts
pass parameter to Javascript
Jul 31, 2003 03:40 PM|LINK
Atrax
All-Star
18705 Points
3733 Posts
Re: pass parameter to Javascript
Jul 31, 2003 04:13 PM|LINK
Jason Brown - MVP, IIS
rox.scott
Contributor
6080 Points
1214 Posts
Re: pass parameter to Javascript
Jul 31, 2003 04:24 PM|LINK
btnAddSymChange.Attributes.Add("onClick", "return ValidateText('" + txtChValue.Text + "')")ORbtnAddSymChange.Attributes.Add("onClick", "return ValidateText(txtChValue.Text)")rox.scott
Contributor
6080 Points
1214 Posts
Re: pass parameter to Javascript
Jul 31, 2003 04:27 PM|LINK
btnAddSymChange.Attributes.Add("onClick", "return ValidateText(document.all.txtChValue.value)")jkj1998
Member
15 Points
3 Posts
Re: pass parameter to Javascript
Jul 31, 2003 05:24 PM|LINK
jkj1998
Member
15 Points
3 Posts
Re: pass parameter to Javascript
Jul 31, 2003 06:09 PM|LINK
rox.scott
Contributor
6080 Points
1214 Posts
Re: pass parameter to Javascript
Aug 01, 2003 06:10 AM|LINK
function ValidateSymChange(symChangeValue) { if(isWhitespace(symChangeValue)) return false; return true; }