string formatting an anchor which has to call a javascript function onclick(mvc)
asp.net-mvc, c#, javascript
Solution
Finally I fixed the issue. The main problem is passing the arguments to the script function. we have to pass some thing like goog_report_conversion(567678899);
For that I had used regex.replace function to remove special characters like below
Regex.Replace(sPhone,"[()' '-]","");
and passed that in the place of parameter at function call. now my generated html looks like below
<a onclick="Javascript: goog_report_conversion(2818669180); return false;" href="tel:(281) 866-9180">(281) 866-9180</a>
So, Finally I fixed my issue in the above manner. Thanks to all who tried to help me....
Problem
``` goog_snippet_vars = function(){ var w = window; w.google_conversion_id ="xxxxx"; w.google_conversion_label ="xxxxxx"; w.google_conversion_value ="xxxxxx"; }, goog_report_conversion = function(url) { goog_snippet_vars(); window.google_conversion_format = '3'; window.google_is_call = true; var opt = new Object(); opt.onload_callback = function() { if (typeof(url) != 'undefined') {window.location = url;} } var conv_handler = window['google_trackConversion']; if (typeof(conv_handler) == 'function') {conv_handler(opt);} } </script> ``` I am dumping the above code in to a page(onload) using stringbuilder from server. and i am using string.format to generate html from server side to the telephone no displayed on the webpage , which on click have to call one of the functions in above script. I used the below code for that ``` string.Format("<a href=\"tel:{0}\" onclick=\"Javascript: goog_report_conversion(tel{0}); return false;\">{0}</a>", PhoneNumber)); ``` everything is fine html is applying to the tele no. the issue is on click it is not hitting the function , its simply navigating to new page with url as href value. so please help me if any work around is there.....thanks...