0

I am working on Sharepoint App. Their is one functionality to get the contact details from the sharepoint site list. Here is my piece of code:

var currentOpeningContent = '<h4 onclick="ShowJobDetail(\'' + encodeURI(currentOpeningTitle.text()) + encodeURI(currentOpeningRR.text()) '\');">'+Show details+'</h4>';

$("#open_jobs").append(currentOpeningContent);

function ShowJobDetail(title, roles)
{
    $(".job_page_title").html(decodeURI(title));
    $(".job_roles").html(decodeURI(roles));
}

The only issue is that when an email id is passed in the "roles", it becomes a plain text because of decodeURI. But what i want is when an user clicks on the email id, popup window should open.

Dilip Kumar Yadav
  • 565
  • 1
  • 7
  • 27
  • It would be helpful to see example values for currentOpeningTitle.text and currentOpeningRR.text. Also see question: [mailto using javascript](http://stackoverflow.com/questions/10172499/mailto-using-javascript) – Yogi Mar 15 '16 at 12:06

1 Answers1

0

I don't fully understand your problem but I think the code is broken.

As you're already using jQuery, instead of doing this ugly thing:

var currentOpeningContent = '<h4 onclick="ShowJobDetail(\'' 
    + encodeURI(currentOpeningTitle.text())
    + encodeURI(currentOpeningRR.text()) '\');">'
    + Show details
    + '</h4>';

$("#open_jobs").append(currentOpeningContent);

Please do it like that:

var $currentOpeningContent = $('<h4>Show details</h4>').click(encode);

function encode(e){
    var title = '' + encodeURI(currentOpeningTitle.text()) + encodeURI(currentOpeningRR.text());

    ShowJobDetail(title, roles); //"roles" is undefined! that's probably not wat you want
}

$("#open_jobs").append($currentOpeningContent);

This is a 1:1 "transcript" of your code. You can see that "roles" is undefined when you click the 'h1'. It seems that you just forgot a coma between your function arguments.

NOTE: never put JS in an HTML string explicitly. That's just asking for trouble. Also - when using jQuery - try avoiding plain html strings in favour of jQuery "HTML-generating" methods.

Piotr Ma'niak
  • 698
  • 8
  • 17