Results 1 to 9 of 9

Thread: html variable help

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Nov 2004
    Posts
    22

    html variable help

    I have the following html code:

    </SCRIPT>
    <script language="JavaScript">
    <!--
    function OpenAbout()
    {
    var centerWidth=(screen.width/2)-(680/2);
    var centerHeight=(screen.height/2)-(600/2);
    var sReportName = "about.aspx"
    winpops=window.open
    (sReportName,"_blank","height=600,width=680,top="+centerHeight+",left="+centerWidth+",toolbar=0,loca tion=0,directories=0,status=0,scrollbars=0,menubar=0,resizable=0,")
    }
    //-->
    </script>

    Can I change the line:
    var sReportName = "about.aspx"

    so that "about.aspx" is equal to the text of a combo box on the web page?
    Dave G

  2. #2
    Hyperactive Member tailz's Avatar
    Join Date
    Jul 2002
    Posts
    306

    Re: html variable help

    the first parameter of the window.open command is the URL for the page

    so yes you can do what you like with it

    edit:

    and I have just realised you are asking how to change the line, I'll make summat up for you, 5 mins
    Last edited by tailz; Dec 21st, 2004 at 12:45 PM.

  3. #3
    Hyperactive Member tailz's Avatar
    Join Date
    Jul 2002
    Posts
    306

    Re: html variable help

    Modified the javascript slightly and there is a dropdownlist in there somewhere.

    HTML Code:
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
    <HTML>
    	<HEAD>
    		<title>TailzCombo</title>
    		<meta name="GENERATOR" content="Microsoft Visual Studio.NET 7.0">
    		<meta name="CODE_LANGUAGE" content="Visual Basic 7.0">
    		<meta name="vs_defaultClientScript" content="JavaScript">
    		<meta name="vs_targetSchema" content="http://schemas.microsoft.com/intellisense/ie5">
    		<script language="JavaScript">
    		<!--
    		function OpenPopup(sReportName)
    		{
    			var centerWidth=(screen.width/2)-(680/2);
    			var centerHeight=(screen.height/2)-(600/2);
    			winpops=window.open(sReportName,"_blank","height=600,width=680,top="+centerHeight+",left="+centerWidth+",toolbar=0,location=0,directories=0,status=0,scrollbars=0,menubar=0,resizable=0,")
    		}
    		//-->
    		</script>
    	</HEAD>
    	<body MS_POSITIONING="FlowLayout">
    		<form id="Form1" method="post" runat="server">
    			<asp:DropDownList id="DropDownList1" runat="server" onchange="javascript:OpenPopup(this.value)">
    				<asp:ListItem Value="http://www.vbforums.co.uk/" Selected="True">vbforums</asp:ListItem>
    				<asp:ListItem Value="http://www.PosterCash.co.uk/">PosterCash :]</asp:ListItem>
    			</asp:DropDownList></TD>
    		</form>
    	</body>
    </HTML>

  4. #4

    Thread Starter
    Junior Member
    Join Date
    Nov 2004
    Posts
    22

    Re: html variable help

    what do I type instead of:

    var sReportName = "about.aspx"


    what do i replace the "about.aspx" with.

    my combo box is populated from a database can i reference the text property??
    Dave G

  5. #5
    Hyperactive Member tailz's Avatar
    Join Date
    Jul 2002
    Posts
    306

    Re: html variable help

    Have you even tried that code I pasted?

    It references the .Value property of the selected item in the combobox.

  6. #6

    Thread Starter
    Junior Member
    Join Date
    Nov 2004
    Posts
    22

    Re: html variable help

    Thanks

    Sorry for not seeing that.

    I would like to however only open the window if a (panel for example) is visible on the screen.

    can i set a varible in the HTML script to equal a variable from the vb code.

    i.e.

    var bselected= "var in vb code"
    Dave G

  7. #7
    Hyperactive Member tailz's Avatar
    Join Date
    Jul 2002
    Posts
    306

    Re: html variable help

    You can inject javascript but I think you can also do this;

    HTML Code:
    <script language="JavaScript">
    		<!--
    		function OpenPopup(sReportName)
    		{
    			var sReportName=<% =FunctionInVB()%>
    			var centerWidth=(screen.width/2)-(680/2);
    			var centerHeight=(screen.height/2)-(600/2);
    			winpops=window.open(sReportName,"_blank","height=600,width=680,top="+centerHeight+",left="+centerWidth+",toolbar=0,location=0,directories=0,status=0,scrollbars=0,menubar=0,resizable=0,")
    		}
    		//-->
    </script>
    then just create

    VB Code:
    1. Function FunctionInVB() As String
    2.     Return "about.aspx"
    3. End Function

    Don't believe thats the neatest way to do it. you should look at "injecting" javascript into your code

  8. #8

    Thread Starter
    Junior Member
    Join Date
    Nov 2004
    Posts
    22

    Re: html variable help

    Think I'm getting somewhere (thanks for the help).

    One last problem (I hope)

    I have the following function

    function OpenReport()
    {
    var centerWidth=(screen.width/2)-(680/2);
    var centerHeight=(screen.height/2)-(600/2);
    var sReportName = <% =GetTargetPage()%>
    var machinecount= <% =GetMachineCount()%>

    if (machinecount != 0)
    {
    winpops=window.open
    (sReportName,"_blank","height=600,width=680,top="+centerHeight+",left="+centerWidth+",toolbar=0,loca tion=0,directories=0,status=0,scrollbars=0,menubar=0,resizable=0,");
    }
    }

    My problem is that sReportName equals:

    '../Reports/MachineStatus.aspx?StartDateTime=23/12/2004 05:45:00& EndDateTime=23/12/2004 17:45:00?MachineType='Filler14, Filler13'&MachineCount=2'

    (when I pass it from the vb script I have to add ' to the beginning and wnd for it to work)

    This errors due to the extra ' on the machine type. Is there a way round this?

    Thanks
    Dave G

  9. #9

    Thread Starter
    Junior Member
    Join Date
    Nov 2004
    Posts
    22

    Re: html variable help

    Just ommitted the ' .

    Works


    Thanks for all your help. really appreciate it.
    Dave G

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width