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!

Combine functionalities of two buttons

Status
Not open for further replies.

tmcneil

Technical User
Nov 17, 2000
294
US
I have two buttons on an asp page that are the following:
Code:
<button ID="PREVIEW" name="PREVIEW" value="PREVIEW" type="button" title="Preview Webpage" 
                    onClick="Submit('Preview Webpage');" class="dlgbutton" style="width: 140px;">
                    <span>Preview Webpage&nbsp;</span>
                </button><br><br>
                <button ID="DISPLAY" name="DISPLAY" value="DISPLAY" type="button" title="Display Webpage" 
                    onClick="PopWin('<%=urlOutput%>');" <% if urlOutput = "" then %> disabled <% end if %>
                    class="dlgbutton" style="width: 135px;">
                    <span>Display Webpage&nbsp;</span>
                </button>
 
I hit submit by accident......

The 1st button basically previews a webpage by calling an oracle stored procedure that returns back a url. The 2nd button calls a javascript function to popup a window and display the url. So, if it takes about 10 secs to have the page post and get the resultant url, how can I wait and call the popupwindow javascript function and give it the url....

I would like to combine both steps into one and have one button called Preview Webpage.

Thanks,
Todd
 
Well, the 1st button actually generates the webpage to be previewed in the popup. I use the url that is returned back to point the popup window to. If I call the PopWin() on the onClick, then I am sending an empty variable, because the page has not posted yet....

Does this help? I'm not sure what else to add...

Todd
 
You're trying to mix client side and server side code.

What you are trying to do can be done using AJAX.


[monkey][snake] <.
 
Hi

It is still blurry to me. Let us see what I ( think to ) understood :

Button 1 - sends a request to something on the server
- that something returns an URL
Button 2 - sends a request to that URL
- finally you get the desired result page (*)

And you want to open a pop-up window with the desired result page ( marked above (*) ) without letting the visitor to know about the intermediary steps ?

Feherke.
 
Feherke,

Exactly!

Button 1 - calls an Oracle stored procedure to return a url.

Button 2 - display the url in a popup window that I can resize depending on the screen resolution.

So, I've been working on some AJAX, but was wondering if you had another solution.

Todd
 
Hi

Then why not just redirect ?
[ol]
[li]the unique button sends the request to the ASP[/li]
[li]ASP runs the stored procedure and returns the URL in a redirect header[/li]
[li]the browser automatically follows the redirection and requests the new page[/li]
[/ol]
Code:
<%
[gray]' note that no proper content is sent back[/gray]
[gray]' especially not before sending the redirect[/gray]

url = KindOfOracleConnection.RunSomehowTheStoredProc("the_proc")

Response.Redirect(url)
%>

Feherke.
 
Well,

I've got something here and I decided to use AJAX as I found a good example on the web, but it's not finished yet....

Button on asp page:
Code:
<button ID="PREVIEW" name="PREVIEW" value="PREVIEW" type="button" title="Preview Webpage" 
onClick="Preview('<%=MessageID%>','<%=GetVal("takes", " ")%>','<%=imageFiles%>','<%=captionValues%>');"
class="dlgbutton" style="width: 140px;">
<span>Preview Webpage&nbsp;</span>
</button>

AJAX Javascript calls:
Code:
var xmlHttp;

function Preview(messageID, takes, imageFiles, captionValues)
{ 
    xmlHttp=GetXmlHttpObject();
    if (xmlHttp==null)
    {
        alert ("Your browser does not support AJAX!");
        return;
    }
    xmlHttp.onreadystatechange=stateChanged;
    var params = messageID="+messageID+"&takes="+takes+"&imageFiles="+imageFiles+"&captionValues="+captionValues;
    var url = getPath("amberAlertPreview.asp");
    url=url+"?"+params;
    xmlHttp.open("GET",url,true);
    xmlHttp.send(null);
}

function stateChanged() 
{ 
    if (xmlHttp.readyState == 4)
    { 
        if (xmlHttp.status == 200 || xmlHttp.status == 0)
        {
            //alert(xmlHttp.responseText);
            var url = xmlHttp.responseText;
        }
        else
        {
            alert('There was a problem with the request.');
        }
    }
    PopWin(url);
}

function GetXmlHttpObject()
{
    var xmlHttp=null;
    try
    {
        // Firefox, Opera 8.0+, Safari
        xmlHttp = new XMLHttpRequest();
    }
    catch (e)
    {
        // Internet Explorer
        try
        {
            xmlHttp = new ActiveXObject("Msxml2.XMLHTTP");
        }
        catch (e)
        {
            xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
        }
    }
    return xmlHttp;
}

other Javascript functions needed:
Code:
function getPath(page)
{
	//	Build the location independent path using the current pages 
	//  address to compose a full path...
	dir = location.pathname;
	dir = dir.substring(1, dir.length);
	path = location.protocol + "//" + location.hostname;
	n = dir.indexOf("/");
	if (n != -1)
	{
		dir = dir.substring(0, n);
		path = path + "/" + dir;
	}
	path = path + "/" + page;
	return path;
}// end getPath

function PopWin(url)
{
    //change popup window height and width dynamically
    var Height = 1000;
    var Width  = 1300;
    
    if( (screen.width == 1280) && (screen.height == 1024) ) //1280 x 1024
    {
        Width = 1300;
    }
    else if ( (screen.width == 1152) && (screen.height == 864) )  //1152 x 864
    {
        Height = 900;
        Width = 1200;
    }
    else if ( (screen.width == 1024) && (screen.height == 768) )  //1024 x 768
    {
        Height = 800;
        Width = 1100;
    }

	//FF, window is still offcenter
	if (navigator.appName=="Netscape")
	{
	    window.open(url,"window","status=no,edge=raised,help=no," +
	                "scrollbars=yes,unadorned=yes,resizable=no,width="+Width+",height="+Height);
	}
	
	//IE
	if (navigator.appName=="Microsoft Internet Explorer")
	{
	    showModalDialog(url,window,"status:no;edge:raised;help:no;" +
	                    "scroll:yes;unadorned: yes;resizable:no;dialogWidth:"+Width+";" +
              		    "dialogHeight:"+Height+"px");
	}				
}

amberAlertPreview.asp page:
Code:
<%@ LANGUAGE="VBSCRIPT" %>
<% Response.Expires = 0 %>
<% Response.Buffer = true %>

<!--#include file="include/database.asp"-->
<%  
    '--------------------------------------------------------------------------
    ' MessageID, Takes, imageFiles and captionValues being passed from
    ' Preview(messageID, takes, imageFiles, captionValues) javascript
    ' function
    '--------------------------------------------------------------------------
    MessageID     = GetVal("messageID", 0)
    clips         = GetVal("takes", "")
    imageFiles    = GetVal("imageFiles", "")
    captionValues = GetVal("captionValues", "")
    urlOutput     = GetVal("urlOutput", "")
	    
	'--------------------------------------------------------------------------
    ' Call CreateAmberPreviewRequest
    '--------------------------------------------------------------------------
	Call SetServerInfo()
    Call CreateAmberPreviewRequest(MessageID, clips, imageFiles, captionValues, urlOutput, ErrorMsg, ErrorCode)
    
    '--------------------------------------------------------------------------
    ' Sub CreateAmberPreviewRequest
    '--------------------------------------------------------------------------
	Sub CreateAmberPreviewRequest(MessageID, Takes, imageFiles, captionValues, urlOutput, ErrorMsg, ErrorCode)

	Dim comm
	Set cn = GetDBConnection()
	Set comm = Server.CreateObject("ADODB.Command")
	comm.ActiveConnection = cn
	comm.CommandText = "{CALL Msg_Pkg.CreateAmberPreviewRequest(?,?,?,?,?,?,?) }"
	comm.CommandType = adCmdText

	set param = comm.CreateParameter("MessageID",	    adInteger, adParamInput, ,		MessageID)
	comm.Parameters.Append param
	set param = comm.CreateParameter("Takes",			adVarChar, adParamInput, 1000,	Takes)
	comm.Parameters.Append param
	set param = comm.CreateParameter("imageFiles",		adVarChar, adParamInput, 1000,	imageFiles)
	comm.Parameters.Append param
	set param = comm.CreateParameter("captionValues",   adVarChar, adParamInput, 1000,	captionValues)
	comm.Parameters.Append param
	set param = comm.CreateParameter("urlOutput",       adVarChar, adParamOutput, 1000, urlOutput)
	comm.Parameters.Append param
	set param = comm.CreateParameter("ErrorMsg",	    adVarChar, adParamOutput, 512,	ErrorMsg)
	comm.Parameters.Append param
	set param = comm.CreateParameter("ErrorCode",		adInteger, adParamOutput, ,		ErrorCode)
	comm.Parameters.Append param
	set param = Nothing

	ON ERROR RESUME NEXT
    comm.Execute()
	If GetDBError(cn) = 0 THEN
	  urlOutput     = comm.Parameters("urlOutput").Value
  	  ErrorMsg      = comm.Parameters("ErrorMsg").Value
  	  ErrorCode     = comm.Parameters("ErrorCode").Value
	  status = 0
	Else
	  status = -1
	end if
    Set comm = Nothing

    End Sub
    
    '--------------------------------------------------------------------------
    ' urlOutput
    '--------------------------------------------------------------------------
    response.write(urlOutput)
%>

So, yes it is a long post with alot of code, but I'm getting a quick response back from the server in the function stateChanged(), I do an alert and there is my responsetext as a url. However, when I decide to store the responseText into a variable and call my PopWin() function to popup the window with the url, it takes IE several tries to actually show the page. It is like the url variable is not being passed correctly or stored in a timely manner. FF seems to popup the window and if it is initially unavailable, a sec or two later, the page shows up inside the window. That's ok with me. IE, you have to close the popup 4 times, on the 5th try, there is the page. So, could I write a wait or sleep until the url variable has the value prior to calling the PopWin() function?

Thanks,
Todd
 
Well,

I found the answer. I changed the IE part of PopWin() to use the same window.open as firefox and added the top=0 and the left=0 attribute to open the popup in the upper left corner of the screen. So, all is well now.

Code:
function PopWin(url)
{
    //change popup window height and width dynamically
    var Height = 1000;
    var Width  = 1300;
    
    if( (screen.width == 1280) && (screen.height == 1024) ) //1280 x 1024
    {
        Width = 1300;
    }
    else if ( (screen.width == 1152) && (screen.height == 864) )  //1152 x 864
    {
        Height = 900;
        Width = 1200;
    }
    else if ( (screen.width == 1024) && (screen.height == 768) )  //1024 x 768
    {
        Height = 800;
        Width = 1100;
    }

	//Works for FF and IE
    window.open(url,"window","status=no,edge=raised,help=no,top=0,left=0" +
	            "scrollbars=yes,unadorned=yes,resizable=no,width="+Width+",height="+Height);			
}

Thanks for the input.

Todd
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top