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 Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

help dynamically setting the style of a div

Status
Not open for further replies.

tperri

Programmer
Apr 8, 2006
728
US
Here is what I'm trying to do

I have a hidden div, and when a link is clicked, that div will unhide (this is working). The data on the page is dynamic, so I want to dynamically position that div to unhide near the location of the link that is clicked.

Here is the function to dynmaically set the style:

Code:
    function getPosition(div, obj)
    {
        var yPos = getTop(document.getElementById(obj)) - 50;
        var xPos = getLeft(document.getElementById(obj)) + 50;
        
        if (yPos <= 0)
            yPos = yPos + 100;
            
        //return ("position: absolute; top: " + xPos + "px; left: " + yPos + "px;");
        div.style.cssText = "z-Index:100;position: absolute; top: " + xPos + "px; left: " + yPos + "px;";
    }

And here is the HTML code (served up by ASP.Net)
Code:
<div id="loginpopup" visible="true" runat="server" onload="javascript:getPosition(loginpopup, lnkLogin);">

lnkLogin is the name of my ASP.Net LinkButton control.

I am getting a compliation error when I try to do this, stating "Compiler Error Message: CS1026: ) expected" on the line of my HTML code.

Am I approaching setting the style the wrong way? I'm uncertain why I am getting this error, as I have no open bracets in my onload function of the div.

Your help with this is greatly appreciated!
 
hey tperri, there doesn't seem to be anything wrong with the code that you've supplied. Are you sure that the error is coming from that block of code? That error message doesn't always indicate that a parentheses is missing - for example this block of code will generate the same error message even though the missing + sign to concatenate the last string is the cause of the error:
Code:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "[URL unfurl="true"]http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">[/URL]
<html xmlns="[URL unfurl="true"]http://www.w3.org/1999/xhtml">[/URL]
<head>
<title>test</title>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1" />
<script type="text/javascript">

var a = ("abc" + "def" "xyz");

</script>
<style type="text/css"></style>
</head>
<body>
</body>
</html>

Have you tried loading the page in firefox and looking at the javascript error console to see what it says. It is usually 1000 times more informative and is usually pretty good at pointing out exactly where the error is. For example, in my example above the javascript error console in firefox gave me this:

Code:
Error: missing ) in parenthetical
Source File: file:///C:/Documents%20and%20Settings/HP_Administrator/Desktop/test.html
Line: 8, Column: 23
Source Code:
var a = ("abc" + "def" "xyz");
-----------------------?

Although it still gives roughly the same error message, it still pointed right where the error was to me, and looking at that line from the error console makes it easily apparent that I left out the concatenation operator (+).

-kaht

Lisa, if you don't like your job you don't strike. You just go in every day and do it really half-assed. That's the American way. - Homer Simpson
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top