OnChange event Javascript to call web service
-
Friday, June 01, 2012 8:45 PM
I have a checkbox on a form. When this checkbox is clicked I need it to trigger a webservice. I am still new to SOAP so please let me know is I am doing anything wrong. The error I'm getting is "The value of the property 'startService' is null or undefined, not a Function object" What does that mean?
Here is the javascript I'm using:
function startService(name)
{
var xml = "<?xml version='1.0' encoding='utf-8'?>" +
"<soap:Envelope xmlns:soap='http://schemas.xmlsoap.org/soap/envelope/' "+
" xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance' " +
" xmlns:xsd='http://www.w3.org/2001/XMLSchema'>"+
"<soap:Body>" +
"<createrole xmlns=\'http://tempuri.org/\'>" +
"<name>" + name + "</name>" +
"</createrole>" +
"</soap:Body></soap:Envelope>";
xmlHttp = new ActiveXObject("Msxml2.XMLHTTP");
xmlHttp.open("POST","http://localhost/CreateRoles/Service1.asmx?wsdl", true);
xmlHttp.setRequestHeader("Content-Type","text/xml; charset=utf-8?);
xmlHttp.setRequestHeader("Content-Length",xml.length);
xmlHttp.send(xml);
}I tested to see is "Name" was being passed in properly by changing the code to "alert("hello" + name);" and it worked perfectly. and I kept the function name as startService for the alert change as well. So I know the problem is in the code somewhere. All help is greatly appreciated.
All Replies
-
Saturday, June 02, 2012 12:24 AM
"<createrole xmlns=\'http://tempuri.org/\'>" +
I think using the \ before the ' causes it to escape, this might be one issue.
xmlHttp.setRequestHeader("Content-Type","text/xml; charset=utf-8?);The other is that you're missing a matching ["] in this line.
- Proposed As Answer by David Nidorf Saturday, June 02, 2012 12:24 AM
- Marked As Answer by Billyj82 Monday, June 04, 2012 1:52 PM
-
Monday, June 04, 2012 7:59 AM
Hi
you create following function on load of form
function myFuction()
{
crmForm.all.checkboxfieldname.onclick = function () {crmForm.all.checkboxfieldname.FireOnChange();
};
}then your function on checkbox onChange
function startService(name)
{}
-
Monday, June 04, 2012 1:53 PMRiaz I already had the fireonchange event in my onload. David I made the changes you suggested and works right away. Thanks!! :D