Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Problems passing variables to javascript 1

Status
Not open for further replies.

markronz

IS-IT--Management
Mar 20, 2007
93
US
Hello, me again. I'm making progress, but I'm having some issues passing some arguments to javascript. When I look at my code in my asp, it looks like this:

Code:
output.Append("       <td class='cell'><A id = 'displayText' HREF = '#' onclick='return hideDiv('" & strTargets & "');'>" & strTargets & "</A></td>" & vbNewLine)

When I run my webpage and look at the source, it actually generated lines like this one for example:
HTML:
<td class='cell'><A id = 'displayText' HREF = '#' onclick='return hideDiv('MarketingGroup');'>MarketingGroup</A></td>

My javascript function looks like this:

JavaScript:
<script type="text/javascript"> 
function hideDiv(str) {
	document.getElementById("Results").style.visibility = "hidden";
	document.getElementById("resultsIFrame").src = "aspdbsearchpage.aspx?idvalue=" + str
	document.getElementById("AlertGroupResults").style.visibility = "visible";
} 
</script>

I can't for the life of me figure out why it's not passing through the argument correctly. To me when I look at the generated html code, it looks right to me. I thought for a while it had something to do with the quotes, but it just looks right to me.

According to IE, the errors I am getting are a whole bunch of Syntax errors:
Code:
Webpage error details

User Agent: Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.1; Trident/4.0; SLCC2; .NET CLR 2.0.50727; .NET CLR 3.5.30729; .NET CLR 3.0.30729; Media Center PC 6.0; .NET CLR 1.1.4322; .NET4.0C; .NET4.0E; MS-RTC LM 8; Tablet PC 2.0)
Timestamp: Thu, 11 Oct 2012 20:18:41 UTC


Message: Syntax error
Line: 323
Char: 1
Code: 0
URI: [URL unfurl="true"]http://localhost:3892/AlertHistory/Default.aspx[/URL]

Any idea what I'm doing wrong? To I have extra quotes some where? Not enough? Something else?
 
You can't have single quotes inside single quotes. It confuses the JS parser since it ends the command prematurely.
Code:
onclick=[COLOR=white red]'[/color][red]return hideDiv([/red][COLOR=white red]'[/color][blue]MarketingGroup[/blue]'[red]);[/red]'

And since you are already using double quotes, you'll need to use the HTML entities instead.

Code:
onclick='[green]return hideDiv([red][ignore]&#39;[/ignore][/red]MarketingGroup[red][ignore]&#39;[/ignore][/red]);[/green]'


----------------------------------
Phil AKA Vacunita
----------------------------------
Ignorance is not necessarily Bliss, case in point:
Unknown has caused an Unknown Error on Unknown and must be shutdown to prevent damage to Unknown.

Web & Tech
 
Perfect, that works! I knew it had to be something like that, just couldn't figure it out. Thanks again!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top