?
Solved

Passing a Button ID to a VBScript Variable onClick

Posted on 2009-02-12
15
Medium Priority
?
1,576 Views
Last Modified: 2012-05-06
Greetings,

I need to pass the ID of a button to a variable when the button is click so that I can store it as a Session Variable and pass it to a page.

Basically I have a table that lists orders. Each order then has a button to "view" the details. I use a tiny bit of javascript to open a seperate page with the details in, which are pulled down into a table via ADO from SQL.

Now what initally did was used the recordset and a select SQL statement to pass the "Order No" to a Session Variable when the button was clicked.

The order No is have I display the details on the "view details" page, not until I tried to test viewing another order which had a different order no did I realise that no matter what I do it will pass the last entered Order No from the record set to the Session Variable hence only ever going to show one Order No.

I thought the best way would be to "onClick" get the ID of the button pressed and since the buttons id's are created in the table using the order no's so "button_<%order no variable%>" I could just capture the id of the button clicked, truncate the final digit(s) and pass them to a session variable?

Is this doable or have I made a completely complicated issue out of something that is simple.

All help and views appreciated :) Oh and I've attached some code, just the code that creates the button (via loop) and the javascript that is used for the new window.

<td class="style2"><div align="center"><input type="button" class="style2" id="view_<% = oRs.Fields("Order No")%>" onclick="window.location.href=('javascript:dopopup();x.focus();');" value="View">
</a> </div></td>
 
<script type="text/javascript">
function dopopup()
{
var chrome= "width=600,"
      + "height=483,"
      + "location=0,"
      + "menubar=0,"
      + "resizable=0,"
      + "scrollbars=0,"
      + "status=0,"
      + "titlebar=0,"
      + "toolbar=0,"
      + "hotkeys=0,"
      + "left=0,"
      + "top=0";
      x=window.open('orderdetails_gfx.asp',null,chrome);
      x.parent.document.title="Order Details";
}
</script>

Open in new window

0
Comment
Question by:ADT58
  • 8
  • 7
15 Comments
 
LVL 29

Expert Comment

by:Badotz
ID: 23621473
As an aside, if you don't need a feature for the popup window, there is no need to include, say,

+ "menubar=0,"

because the default for (most) features is "turned off".

You can "reach back" from the popup window to the parent window and (possibly) retrieve the value of the button - or the id of the button - as long as you put the value in a variable declared outside any function:

<td class="style2"><div align="center"><input type="button" class="style2" id="view_<% = oRs.Fields("Order No")%>" onclick="window.location.href=('javascript:dopopup(this);x.focus();');" value="View">

<script type="text/javascript">
 
var button_order = '';
 
function dopopup(button) {
button_order = button.id;
 
// From the popup window:
 
<script type="text/javascript">
var wp = window.parent; // Or "window.opener", I can never remember which :-/
var order_num = wp.button_order;
 
// You will have to strip off the "view_" portion, but this should get you started

Open in new window

0
 

Author Comment

by:ADT58
ID: 23621496
great but how can I get from a javascript variable to a VBScript variable?

Thanks for your help by the way.
0
 
LVL 29

Expert Comment

by:Badotz
ID: 23621548
Do you mean from the CLIENT to the SERVER?
0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 

Author Comment

by:ADT58
ID: 23621849
Its all server side with VBScript I only used a tiny bit of java to just popup the window. I need the order no via whichever button was clicked so I can pass it to a variable to be used in a SELECT SQL statement server side.
0
 
LVL 29

Expert Comment

by:Badotz
ID: 23621890
Create a hidden input and set its value to the JavaScript variable before you submit the page.
0
 

Author Comment

by:ADT58
ID: 23631234
when I did a document.write on the variable all I got was "undefined"

<script type="text/javascript">
var wp = window.opener; // Or "window.opener", I can never remember which :-/
var order_num = wp.button_order;
document.write(order_num);
</script>

That is located in the "popup" window I tried using both opener and parent.

<input type="button" class="style2" id="view_<% = oRs.Fields("Order No")%>" onclick="window.location.href=('javascript:dopopup(this);x.focus();');" value="View">

This is located at the end of the body in the "main" page.

<script type="text/javascript">
 
var button_order = '';
 
function dopopup(button) {
button_order = button.id;
</script>
<script type="text/javascript">

var button_order = '';
 
function dopopup(button)
{
button_order = button.id;

var chrome= "width=600,"
      + "height=483,"
      + "location=0,"
      + "menubar=0,"
      + "resizable=0,"
      + "scrollbars=0,"
      + "status=0,"
      + "titlebar=0,"
      + "toolbar=0,"
      + "hotkeys=0,"
      + "left=0,"
      + "top=0";
      x=window.open('orderdetails_gfx.asp',null,chrome);
      x.parent.document.title="Order Details";
}
</script>

Sorry if I'm useless but I don't have a clue when it comes to Javascript :(

0
 
LVL 29

Expert Comment

by:Badotz
ID: 23631338
Is this just a typo?

<script type="text/javascript">
 
var button_order = '';
 
function dopopup(button) {
button_order = button.id;
</script>
<script type="text/javascript">

var button_order = '';
 
function dopopup(button)
{
button_order = button.id;

Because you don't need the first 7 lines...
0
 

Author Comment

by:ADT58
ID: 23631430
Sorry type my bad..

0
 

Author Comment

by:ADT58
ID: 23631431
*typo
0
 
LVL 29

Expert Comment

by:Badotz
ID: 23634438
hmmm...
<script type="text/javascript">
 
var button_order = '';
 
function dopopup(button) {
    button_order = button.id;
    
    var chrome= "width=600,height=483";
    var x = window.open('orderdetails_gfx.asp',null,chrome);
    
//  x.parent.document.title = "Order Details"; // "x.parent"? Isn't this the window.opener??
    
    // I would try:
    
    x.document.title = 'Order Details:' + button.id; // Tack the ORDER# onto the end of the title
    x.document.close(); // VERY important to do this.
}
</script>

Open in new window

0
 

Author Comment

by:ADT58
ID: 23647971
Tried it, got nothing in the Title bar I'm afraid just had "Mozilla Firefox" for FF and the URL for IE. Really starting to bug me this is :S

I think what I may have to do is just resort to radio buttons with a button on the bottom for Viewing and losing the individual buttons, not the prefered option but may be the only one by the looks.

Any other thoughts at all?
0
 
LVL 29

Expert Comment

by:Badotz
ID: 23648076
Not the title bar, the document title (var dt = document.title;)
0
 

Author Comment

by:ADT58
ID: 23648756
I'm fniding it difficult to understand what your suggesting Badotz, I have pasted the code you have gave me here there and everywhere and still get no results at all. I'm struggling to understand on the basis of I know nothing at all to do with Javascript.

I think I might be better off just creating radio buttons and having the form post back to the same page and depending on which radio button is selected, opening the window on that basis. I know this can be achieved through VBScript but nothing this way is seeming to work.
0
 
LVL 29

Accepted Solution

by:
Badotz earned 1000 total points
ID: 23650961
If you can get the ID of the button into the hidden text field, something you can do in the "onclick" event, then you can add the VALUE of that hidden field to the "document.title" of the new window, as I described in http:#a23634438.
0
 
LVL 29

Expert Comment

by:Badotz
ID: 23658391
So, did it work?
0

Featured Post

How to Use the Help Bell

Need to boost the visibility of your question for solutions? Use the Experts Exchange Help Bell to confirm priority levels and contact subject-matter experts for question attention.  Check out this how-to article for more information.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I was asked about the differences between classic ASP and ASP.NET, so let me put them down here, for reference: Let's make the introductions... Classic ASP was launched by Microsoft in 1998 and dynamically generate web pages upon user interact…
This demonstration started out as a follow up to some recently posted questions on the subject of logging in: http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/Q_28634665.html and http://www.experts-exchange.com/Programming/…
Please read the paragraph below before following the instructions in the video — there are important caveats in the paragraph that I did not mention in the video. If your PaperPort 12 or PaperPort 14 is failing to start, or crashing, or hanging, …
Whether it be Exchange Server Crash Issues, Dirty Shutdown Errors or Failed to mount error, Stellar Phoenix Mailbox Exchange Recovery has always got your back. With the help of its easy to understand user interface and 3 simple steps recovery proced…

839 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