Solved

ASP with Javascript

Posted on 2002-06-22
22
384 Views
Last Modified: 2008-03-10
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?
0
Comment
Question by:buhareb
  • 8
  • 7
  • 3
  • +4
22 Comments
 
LVL 6

Expert Comment

by:Nitin Sontakke
ID: 7101046
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.
0
 
LVL 6

Expert Comment

by:Nitin Sontakke
ID: 7101048
No offence, in case you smell any in my comments above.
0
 
LVL 23

Expert Comment

by:naveenkohli
ID: 7101049
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.
0
 

Expert Comment

by:verybut
ID: 7101120
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>
0
 
LVL 29

Expert Comment

by:Göran Andersson
ID: 7101121
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');
0
 

Author Comment

by:buhareb
ID: 7101466
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
%>
0
 

Author Comment

by:buhareb
ID: 7101470
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!!
0
 
LVL 6

Expert Comment

by:Nitin Sontakke
ID: 7101483
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>

0
 

Author Comment

by:buhareb
ID: 7101501
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.
0
 
LVL 6

Expert Comment

by:Nitin Sontakke
ID: 7101509
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.
0
 

Author Comment

by:buhareb
ID: 7101527
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.
0
Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

 
LVL 6

Expert Comment

by:Nitin Sontakke
ID: 7101541
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?
0
 
LVL 6

Expert Comment

by:Nitin Sontakke
ID: 7101543
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?
0
 

Author Comment

by:buhareb
ID: 7101549
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.
0
 
LVL 6

Expert Comment

by:Nitin Sontakke
ID: 7101580
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.

0
 
LVL 5

Expert Comment

by:kcm76
ID: 7103464
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
0
 
LVL 29

Expert Comment

by:Göran Andersson
ID: 7106820
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>
---------------------
0
 
LVL 6

Expert Comment

by:Nitin Sontakke
ID: 7106889
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.
0
 

Author Comment

by:buhareb
ID: 7107073
ok give me sometime to get these things together
0
 

Author Comment

by:buhareb
ID: 7132719
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
0
 
LVL 29

Accepted Solution

by:
Göran Andersson earned 200 total points
ID: 7137678
I don't understand why you would have to change the workflow of your script? All that my example does is opening a window with a parameter in the query string, then in the opened window pick up that parameter. How does that differ from what you are trying to do?

There is no spaces or such in your script that you can remove that will change it's behaviour.

Now I realised why you tried to use HTTP_REFERER - to get the parameter from the querystring, right? Well, just use Request.Querystring instead.

You have only posted the code for opening the window, so far. I would like to see the code where you try to pick upp the parameter. The code for sending the parameter is correct, so the problem has to be where you recieve the parameter.
0
 
LVL 4

Expert Comment

by:Wakie
ID: 9355434
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.
0

Featured Post

Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
cleaning xml string 2 46
CSS Question.. 3 72
Auto Submit on dropdown box 3 35
Classic ASP - problem with MS SQL Select Query? 10 43
I recently decide that I needed a way to make my pages scream on the net.   While searching around how I can accomplish this I stumbled across a great article that stated "minimize the server requests." I got to thinking, hey, I use more than one…
Hello, all! I just recently started using Microsoft's IIS 7.5 within Windows 7, as I just downloaded and installed the 90 day trial of Windows 7. (Got to love Microsoft for allowing 90 days) The main reason for downloading and testing Windows 7 is t…
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.

708 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now