creating a new window with a fixed size using asp and javascript

I am trying to get my image button to pull my pop-up window but its not working. It does work on other pages and I know whats wrong, so I would like to put the javascripting within my asp section but not sure how to code it in there.

Here is the javascript section that I am using.

<script language="JavaScript" type="text/javascript">
<!--
function goto_reqres2(frm) {
            
            passStr = "popuppage.asp?ID=" + frm.recid.value;
            window.open(passStr,"","toolbar=no, location=no,menubar=no, scrollbars=yes, width=785, height=480, status=no, resizable=yes");
}
//-->
</script>

Here is the image button that it relates to...

Response.Write("<td width='72%'align='left'><span style=""cursor: pointer;"" onClick=""document.getElementById('recid').value=" & rs2("ID") & ";goto_reqres2(document.data)"">" & "<img src=../imagestwo/cont2.gif border='0' alt='History' width='60' height='16'>&nbsp&nbsp&nbsp</span>")

I would like the scripting part be with the asp part of the section.  

I have 3 image buttons that call 3 different pages that I need this for. I appreciate any help you can give me.

Thanks,

Vic
vdornanAsked:
Who is Participating?
 
hieloConnect With a Mentor Commented:
>>for some reason it is going to the last entry for that person
When this executes:
url = "popup.asp?ID=" & rs2("ID")

url will contain a value similar to: popup.asp?ID=3

which is what the browser will get. If you are iterating over a list of DB records, basically what you are doing is this:

<script>
function myPopUp(){window.showModalDialog('popup.asp?ID=1', window, 'dialogHeight: 480px; dialogWidth: 785px; edge: Raised; center: Yes; help: Yes; resizable: Yes; status: No;');};
</script>

<script>
function myPopUp(){window.showModalDialog('popup.asp?ID=2', window, 'dialogHeight: 480px; dialogWidth: 785px; edge: Raised; center: Yes; help: Yes; resizable: Yes; status: No;');};
</script>

Notice how the ID in the url is the only part that changes. Essentially you are writing the same function to the browser multiple times. Ultimately only the last definition is the "valid" one. Hence:
"last entry for that person". You need to write the function outside of the while loop that is iterating over the records and instead declare a function argument:

    response.write("<script>" & vbCrLf)
    response.Write("function myPopUp(ID){window.showModalDialog('popup.asp?ID='+ID, window, 'dialogHeight: 200px; dialogWidth: 300px; edge: Raised; center: Yes; help: No; resizable: No; status: No;');};" & vbCrLf)
    response.write("</script>")

'then do your db stuff
'connect to db, query db, then
while NOT rs.eof
    Response.write("<img src='' alt='' onclick='myPopUp("&rs("ID").value&");'>")
 rs.movenext
wend
0
 
R_HarrisonCommented:
You would have to response.write each line of the javascript, swap quotes for double quotes and add a vbcrlf at the end of each line, see below:

response.write("<script language=""JavaScript"" type=""text/javascript"">" & vbcrlf
response.write("<!--" & vbcrlf
response.write("function goto_reqres2(frm) {" & vbcrlf
response.write("            passStr = ""popuppage.asp?ID="" + frm.recid.value;" & vbcrlf
response.write("            window.open(passStr,"""",""toolbar=no, location=no,menubar=no, scrollbars=yes, width=785, height=480, status=no, resizable=yes"");" & vbcrlf
response.write("}" & vbcrlf
response.write("//-->" & vbcrlf
response.write("</script>" & vbcrlf
0
 
ThinkPaperIT ConsultantCommented:
remember to put the end parenthesis ) at the end of each response.write   =)
0
Never miss a deadline with monday.com

The revolutionary project management tool is here!   Plan visually with a single glance and make sure your projects get done.

 
vdornanAuthor Commented:
I am still getting the same error..... it can't read my hidden field.... How would I go about forcing it to retrieve the value of rs2("ID").

My other image button which just goes to another page works just fine. This is the code for the one that works:
Response.Write("<a href=popup2.asp?ID=" & rs2("ID") & ">" & "<img src=../imagestwo/edit2.gif border='0' alt='Edit Record' width='60' height='16'></a>&nbsp&nbsp&nbsp")

It just seems the ones that open to a new window are the ones having the issue....
0
 
hieloCommented:
Your syntax look fine. You need to make sure that:
1. the hidden field has an id="recid". If you it has only name="recid", then document.getElementById("recid") will return null
2. Make sure that rs2("ID") actually has a value. If it is a recordset, then try: rs2("ID").value
0
 
vdornanAuthor Commented:
The hidden field works on my other pages without a problem.

This line works just fine to get to the next asp page,  Is there a way to modify it to have it pop to a new window. All within the ASP code.

Response.Write("<a href=popup2.asp?ID=" & rs2("ID") & ">" & "<img src=../imagestwo/edit2.gif border='0' alt='Edit Record' width='60' height='16'></a>&nbsp&nbsp&nbsp")
0
 
hieloCommented:
On your original post I see:
goto_reqres2(document.data)
if you have:
<form name="data"...>
then try:
goto_reqres2(document.form.data)
0
 
hieloCommented:
To clarify my logic, this will be undefined:
 frm.recid.value

if frm is not a reference to the form object where you hidden field exists. That's why you need to pass:
documeng.form.data

BUT your <form> tag needs to have the name attribute:
<form name="data"...>
0
 
vdornanAuthor Commented:
hielo, I tried that and I get document.form.data is null or not an object.
0
 
hieloCommented:
Can you post the HTML generated by you ASP.
0
 
jarwCommented:
Try using document.forms.data instead (note the added "s").

You could also try something like the code below and avoid using the form altogether. That sort of depends on what you're trying to do.
<%@ language=vbscript %>
<html>
<head>
 
<script language="JavaScript" type="text/javascript">
<!--
function showPopup(id)
{
   var url = "popuppage.asp?ID=" + id;
   window.open(url, "", "toolbar=no,location=no,menubar=no,scrollbars=yes,width=785,height=480,status=no,resizable=yes");
}
//-->
</script>
 
</head>
<body>
 
<%
' Do stuff to open your recordset (rs2)...
%>
 
<span style="cursor:hand;" onclick="showPopup(<%=rs2("ID")%>);"><img src="your_image.gif"></span>
 
<%
' Do stuff to close your recordset...
%>
 
</body>
</html>

Open in new window

0
 
vdornanAuthor Commented:
I got this code to work, but I need to modify it to be when an image is clicked. It seems to popup as soon as the page is opened instead of when the image (button) is selected.

I am not real familiar with javascripting. Thank you for all of your help....

<%
TestVar = False

If TestVar = False Then
    url = "popup.asp?ID=" & rs2("ID")
    response.write("<script>" & vbCrLf)
    response.Write("onload = function(){window.showModalDialog('" & url & "', window, 'dialogHeight: 200px; dialogWidth: 300px; edge: Raised; center: Yes; help: No; resizable: No; status: No;');};" & vbCrLf)  
    response.write("</script>")
Else
    url = "popup.asp?ID=" & rs2("ID")    response.write("<script>" & vbCrLf)
    response.Write("onload = function(){window.showModalDialog('" & url & "', window, 'dialogHeight: 200px; dialogWidth: 300px; edge: Raised; center: Yes; help: No; resizable: No; status: No;');};" & vbCrLf)
    response.write("</script>")  
End If
%>  
0
 
hieloCommented:
>> It seems to popup as soon as the page is opened
Thats because of:
onload = function...

as soon as the page finishes loading, the function will be called automatically.

In your case you need to add an onclick event handler to the <img> in question. So you would need something similar to:
<%
TestVar = False
 
If TestVar = False Then
    url = "popup.asp?ID=" & rs2("ID")
    response.write("<script>" & vbCrLf) 
    response.Write("function myPopUp(){window.showModalDialog('" & url & "', window, 'dialogHeight: 200px; dialogWidth: 300px; edge: Raised; center: Yes; help: No; resizable: No; status: No;');};" & vbCrLf)  
    response.write("</script>")
    Response.write("<img src='' alt='' onclick='myPopUp();'>") 
Else
    url = "popup.asp?ID=" & rs2("ID")    
    response.write("<script>" & vbCrLf) 
    response.Write("function myPopUp(){window.showModalDialog('" & url & "', window, 'dialogHeight: 200px; dialogWidth: 300px; edge: Raised; center: Yes; help: No; resizable: No; status: No;');};" & vbCrLf) 
    response.write("</script>") 
    Response.write("<img src='' alt='' onclick='myPopUp();'>") 
End If
%>  

Open in new window

0
 
vdornanAuthor Commented:
Hielo, that worked but for some reason it is going to the last entry for that person....

They way it works is you select a person from a drop down and you are able to retrieve their open records.

This is what I have and I'm sure I am missing something.

The popup works for this one but goes to the last entry when a person has more than one...

url = "popup.asp?ID=" & rs2("ID")
Response.Write("<td width='72%' align='left'>")
response.write("<script>" & vbCrLf)
response.Write("function myPopUp(){window.showModalDialog('" & url & "', window, 'dialogHeight: 480px; dialogWidth: 785px; edge: Raised; center: Yes; help: Yes; resizable: Yes; status: No;');};" & vbCrLf)  
response.write("</script>")
Response.write("<img src=../imagestwo/cont2.gif border='0' alt='Containment History' width='60' height='16' onclick='myPopUp();'>&nbsp&nbsp&nbsp")

This one works the way its supposed too but just goes to another asp page.

Response.Write("<a href=popup2.asp?ID=" & rs2("ID") & ">" & "<img src=../imagestwo/edit2.gif border='0' alt='Edit Record' width='60' height='16'></a>&nbsp&nbsp&nbsp")

Almost there... Thank you again.
0
 
vdornanAuthor Commented:
It worked... I had a little rework but it worked.... Thank you so much.....
0
All Courses

From novice to tech pro — start learning today.