简体   繁体   中英

Javascript syntax error when passing parameters to a function

I'm not sure how to code this as I may be running into the server side rendering versus client side. It's been a while since I did something like this therefore your input is very helpful.

I'm using a modal popup extender to display a message that is fetched from a database and is rendered in label inside a gridview. My ideas was to use the JavaScript function that is responsible for showing the modal popup. Initial method was to send two params to the function, one being the "this" keyword and the other the message itself as rendered by the .net <%# Eval("Message") %>. This however gave me all kind of syntactical trouble. It should have been as simple as OnClientClick='showComfirm(this, <%# Eval("Message") %>); return false;' OnClientClick='showComfirm(this, <%# Eval("Message") %>); return false;' but wasn't.

Then I thought I can just use the document.getElementById(ct100_ContentsPlaceholder1_hEmailMessage).value . This works but what doesn't is, assigning the value of the label in the popup. Here some code:

function displayInfo(source, message){
   this._source = source;
   var emailBody = document.getElementById("ct100_ContentsPlaceholder1_hEmailMessage).value;
   document.getElementById("ct100_ContentsPlaceholder1_lblPopUpMessage").value = emailBody; // This is where I'm trying to assing text property.
   this._popup - $find('mdlPopup'); 
   this._popup.show();
}

The "message" parameter is what I described at the top as my initial method, which I still would like to make it work.

Anyway, lot of explanation, but would like your input as to why I get syntax error in my initial attempt, as well as why am I not able to assign the value to the text property of the lblPopUpMessage.

Thanks, Risho

UPDATE

The javascript errors I was getting were due to the text which the varialble "message" contains. The varialbe contains plain English text such as a email message, with upper case, lower case letters, exclamation marks, commas, periods, appostrophies, double quotes, space, etc. How do I know this? I've removed all the text save one random word in the message cell in the database and the errors went away. Still could not display the single workd message though.

So is there a workaround for this?

Thanks, R.

You copy + paste the code ? If so, you got a syntax error. This is the good code:

   function displayInfo(source, message){
       this._source = source;
       var emailBody = document.getElementById("ct100_ContentsPlaceholder1_hEmailMessage").value;
   document.getElementById("ct100_ContentsPlaceholder1_lblPopUpMessage").value = emailBody;
   this._popup - $find('mdlPopup'); 
   this._popup.show();
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM