Link to home
Start Free TrialLog in
Avatar of buhareb
buhareb

asked on

ASP with Javascript

I am trying to pass the ID parameter from page to another, using New Window Attribute of JavaScript, Thus i have to include the ID parameter inside the JavaScript itself (by the way i use VBScript as a Server-Side with ASP) but the JavaScript is used to open a new window only.

And the problem is that it opens the new window and submits the form but it doesn't pass the ID parameter thru the form!! i am using the following script:

<SCRIPT language="JavaScript">
<!--
function my_win()
{
window.open('../subject_send_form.asp?ID=" + strID + "%>','mywindow','width=500,height=300,toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,copyhistory=no,resizable=yes');
}
//-->
</SCRIPT>

If you can notice that the page name is (subject_send_form.asp) and i am using a Query String to pass the ID parameter. But as i mentioned it doesn't pass the ID.. !! Any clue?
Avatar of Nitin Sontakke
Nitin Sontakke
Flag of India image

First, i didn't understand the purpose of the whole of this exercise. Anyway.

We can look into that in detail soon, but to begin with where is the opening tag of '%>' in above code.

From where does the value of the strId is coming?

If possible, could you please post the html here so that we all can see what exactly you are up to.

Unless you have a truely unique requirement, whatever you are doing can be done is a highly simplistic way.
No offence, in case you smell any in my comments above.
Avatar of naveenkohli
naveenkohli

From where are you getting the ID value. Is it a global variable in your page? Or you intended to pass it as function parameter and then forgot about it. Or is it server side variable and you are missing opening <% tag.
if strID is defined in asp
try this:
<SCRIPT language="JavaScript">
<!--
function my_win()
{
window.open('../subject_send_form.asp?ID=<%=strID%>','mywindow','width=500,height=300,toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,copyhistory=no,resizable=yes');
}
//-->
</SCRIPT>

if strID is client js variable,and %> is parameter uwant to transfer,try this:
<SCRIPT language="JavaScript">
<!--
function my_win()
{
window.open('../subject_send_form.asp?ID=' + strID + '%25%3E','mywindow','width=500,height=300,toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,copyhistory=no,resizable=yes');
}
//-->
</SCRIPT>
To put a value from asp in the string used in javascript:

window.open('../subject_send_form.asp?ID=<%=strID%>','mywindow','width=500,height=300,toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,copyhistory=no,resizable=yes');

Or, you can put the value in a javascript variable, then use that:

var id='<%=strId%>';
window.open('../subject_send_form.asp?ID='+id,'mywindow','width=500,height=300,toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,copyhistory=no,resizable=yes');
Avatar of buhareb

ASKER

This is the Whole script..

<!--#include file ="../db_conn.asp"-->
<%

strID = Request.QueryString("ID")

Set objRS = Server.CreateObject("ADODB.Recordset")    
     strSQL = "SELECT * FROM aqeeda WHERE ID=" & strID & ""
     objRS.Open strSQL, conn

%>
<html>

<head>
<meta http-equiv="Content-Type" content="text/html; charset=windows-1256">

<SCRIPT language="JavaScript">
<!--
function my_win()
{
window.open('<%=../subject_send_form.asp?ID=" + strID + "%>','mywindow','width=500,height=300,toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,copyhistory=no,resizable=yes');
}
//-->
</SCRIPT>



<title>New Page 1</title>
</head>

<body>

<div align="center">
  <table border="0" cellpadding="0" cellspacing="0" width="300">
    <tr>
      <td align="center" width="147"><a href="javascript:my_win()"><img border="0" src="http://www.alaser.net/admin/images/sendtofriend_icon.gif" width="115" height="21" alt="Send this article to a friend"></a></td>
      <td align="center" width="149"><a href=<%="print.asp?ID=" & strID & ""%>><img border="0" src="http://www.alaser.net/admin/images/print_icon.gif" width="108" height="21" alt="print this article"></a></td>
    </tr>
  </table>
</div>

</body>

</html>

<%
objRS.Close
Set objRS = Nothing

conn.Close
Set objRS = Nothing
%>
Avatar of buhareb

ASKER

Notice that the script is used to send articles from website to eamil.. it is just like "If you like this article send it to a friend" so the script should pass the article ID which is stored in the database and attach it to the URL where the article is.. in order for  the Recipient to get the full URL of the article.

But it sends the email without the URL!!
Honestly, i haven't given much thought to posted script. However, it will be great if you could modify the function as follows and give it a go.

There seem to be a problem constructing the parameter for window.open.

If it doesn't work, please remember that there is something else to the problem. Also, you should keep seeing the source html by View | Source as it will show up any errors in constructing the javaScript function.

<SCRIPT language="JavaScript">
<!--
function my_win()
{
window.open('../subject_send_form.asp?ID=<%=strID%>','mywindow','width=500,height=300,toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,copyhistory=no,resizable=yes');
}
//-->
</SCRIPT>

Avatar of buhareb

ASKER

This the html view souce results:

<html>

<head>
<meta http-equiv="Content-Type" content="text/html; charset=windows-1256">

<SCRIPT language="JavaScript">
<!--
function my_win()
{
window.open('../subject_send_form.asp?ID=41','mywindow','width=500,height=300,toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,copyhistory=no,resizable=yes');
}
//-->
</SCRIPT>


<title>New Page 1</title>
</head>

<body>
..........
and it sends the email without the URL and the ID.
Personally, i haven't done such a thing before, but is it okay if i question your design?

What happens when you click on the hyperlink? Does the subject_send_form.asp seem to be running?

If yes, have you tried printing value of ID in that asp file with the help of following:

Response.Write Request.QueryString("ID")

It is crucial that this .asp file runs. And if it is running we will probably start looking into that as well.

Kindly arrange to reply my above questions whatever is your answer.
Avatar of buhareb

ASKER

subject_send_form.asp is running when i use the following script in print_send.asp which is passing the ID to subject_send_form.asp:

<a href=<%="../subject_send_form.asp?ID=" & strID & ""%>>

so it pass the ID to subject_send_form.asp and this page has:

strURL = Request.ServerVariable("HTTP_REFERER")

which reads the URL of the article (with the ID for sure) and then pass it to subject_send.asp which sends the article to the recipient.

This is the whole cycle.. which works fine, but i don't want to bother the user going to a new page in the same window and send the article then getting back to the article area.. instead i would like him to have a new window with no tool or menu bar in order to make it easy for him to send the article and eventually close the new window.. where he will stay in the article area.
Good. I think i am generally with you now, if not completely.

However, could you please test with 'Response.Write Request.QueryString("ID")' in 'subject_send_form.asp' if the value is received?
I am sorry, after reading your comments few more times, i know what you are saying....

So important question remains:

Is 'subject_send_form.asp' running when passed as a window.open(...). If it is NOT running this way, i am afraid, you are probably stuck with <A HRef="">.

I am not an expert on this issue, but instinctively i thought that i won't run when i first saw your code. I would love to be wrong. Again, i haven't done it personally so be open for other comments.

As i am typing this, yet another thought dawned on me. Can you not dynamically generate html which has "<A HRef>" in it and then open a new window with this dynamically generated html code. Are you with me?
Avatar of buhareb

ASKER

ok the Response.Write Request.QueryString("ID") is not working.. i mean it doesn't get the ID from the first page when using window.open() but it works when i use <a href> so i think as you said... i will stick to <a href> unfortunately...... but if you got a solution please let me know.
Good.

It's bright sunshine here in UK and i am heading to Hastings for sea for the rest of the Sunday.

When i am back, i will try to play with a bit. But as mentioned before, i FEEL that it won't work. I will try it first hand nonetheless.

The only thing that i can now do probably, is wish you all the best.

I think the problem is not with this page. It is the page that opens this page.

instead of printing Request.QueryString("id") just try to print Request.Querystring.  

KCM
You have to have a typo somewhere in your code. The querystring should certainly work when you open a window.

There is no referer when you open a window, though, so if you want it, you have to construct it from other server variables, and pass it along in the querystring.

Here is a working (tested) example for opening a window. As expected, the referer is empty:

-----default.asp-----
<%
strId="42"
%>
<script>
window.open('Test.asp?id=<%=strId%>','MyWin','');
</script>
---------------------

------Test.asp-------
<html>
<head>
</head>
<body>
Id:<%=Request.QueryString("id")%><br>
Referer:<%=Request.ServerVariables("HTTP_REFERER")%><br>
</body>
</html>
---------------------

To use the referer, construct it and send it along in the querystring:

-----default.asp-----
<%
strId="42"
strReferer="http://" & Request.ServerVariables("SERVER_NAME") & Request.ServerVariables("SCRIPT_NAME")
%>
<script>
window.open('Test.asp?id=<%=strId%>&referer=<%=strReferer%>','MyWin','');
</script>
---------------------

------Test.asp-------
<html>
<head>
</head>
<body>
Id:<%=Request.QueryString("id")%><br>
Referer:<%=Request.QueryString("referer")%><br>
</body>
</html>
---------------------
GreenGhost, yes, finally only after reading your comment, i got on to try it myself, independently and it does work.

buhareb, if you do take window.open approach, give points to GreenGhost.

That apart, now i have started doubting the '../' in the url. Can you give one more try by typing the full url there for the time being? Again, it's just a guess. I am not a particularly structured person. Sorry, about that.
Avatar of buhareb

ASKER

ok give me sometime to get these things together
Avatar of buhareb

ASKER

It didn't work!!!!!!!! instead i have user "target=_blank" >>> it would really be nice if the user wouldn't be bothered with the toolbar and other bars...  but i have tried all the techniques where nothing work?

GreenGhos..
Your idea will work if i changed the workflow of my script, but i couldn't... i have read in one of the ASP website that i should eliminate all the 'spaces' between the words in the Javascript but i haven't tried that! i don't know if that will work! any advise.

Buhareb
ASKER CERTIFIED SOLUTION
Avatar of Göran Andersson
Göran Andersson
Flag of Sweden image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
It appears this question has been abandoned.

I will leave a recommendation in the Cleanup topic area that this question will be:

- Points to GreenGhost -

Please leave any comments here within the next seven days.

DO NOT ACCEPT THIS COMMENT AS AN ANSWER!

Wakie,
EE Cleanup Volunteer.