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 derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Jscript with vbscript 2

Status
Not open for further replies.

EnemyGateIsDown

Technical User
Joined
Oct 3, 2002
Messages
235
Location
GB
Hi Guys,

The extract of code below is supposed to perform the vbscript actions if the user presses cancel when prompted by the jscript response box however whatever the user responds the outcome is the same, where am I going wrong?

Any help is as always greatly appreciated.

Cheers,
Chris

Code:
		<script language = "Javascript">
		Session("delconf") = "0";
		var response = confirm("Do you wish to remove the preference from the pool?")
		if (response == true)
			{
			Session("delconf") = "1";
			}
		</script>

		<%
		if session("delconf") = 1 then
... do the conditional stuff
		End if

 
the javascript is setting the Session("delconf") variable to a string whereas the VBScript is checking to see if it is an integer 1. Either remove the quotes from the JScript or add quotes to the VBScript

Tony
_______________________________________________________________
 
I need more coffee - didnt notice this the first time round...

You are trying to mix clientside code with serverside code which wont work in this case without resubmitting the page to the server. Resubmitting the page is the only way for your serverside code to see anything that has occured clientside.


Tony
_______________________________________________________________
 
As far as I am aware the session object will only work if you are using server side code. As the confirm dialog will not work server side I dont think the script will work at all?

I may be wrong but i think you are confusing server side script with client side script
Client side script like plain old javascript will not talk talk to server side scripts like vbscript in your example.
With asp (sorry if you know this) the <%%> scripts are executed long before the javascript even exists.

You need to send the javacript variable to the server using somthing liek a form or even a redirect with a url parameter that the vbscript can read
eg

Code:
<%
if request("delconf") = 1 then
  response.write("delconf="& 1)     
else%>

<script language = "Javascript">
var response = confirm("Do you wish to remove the preference from the pool?")
if (response == true)
	{
		window.location = "me.asp?delconf="+1
	}
</script>
<%End if%>
view the source code of the resulting files if you press cancel and if you press ok
again sorry if you know this
 
Thanks Tony, is there a better way to do what Im trying to achieve? All I really need is a message box that I can base a condition on in some way so that I can Run or not run the following vb?

Cheers,

Chris
 
Thanks Dave, is there a way I can do this in the single script, I was trying to avoid triggering another script..

Cheers,

Chris
 
Yeah I see what you mean regarding the variable, the vbscript is trying to interrogate the variable before the jscript has set it.. hmmm

Chris
 
what are you trying to do with the vbscript? Can you give me an example
 
I suppose I could resubmit the page after I set the session variable in the jscript condition..

Chris
 
All I want to do is run the following query if the user presses cancel on the pop up box.. eg.

the vb I want to run if the user hits OK on the popup is:

Code:
if len (smultIDs) > 0 then
			Set rsGetRoomIDs = createobject ("ADODB.Recordset")
			GetSQL = "select * from reservations where Group_ID = " & smultIDs
			rsGetRoomIDs.Open GetSQL, db, 3, 1
			if rsGetRoomIDs.recordcount = 2 then
				rsGetRoomIDs.movefirst
				RoomID1 = rsGetRoomIDs("Room_ID").Value
				rsGetRoomIDs.movenext
				RoomID2 = rsGetRoomIDs("Room_ID").Value
				Got_Room_IDs = True
			End if

		'Now get the SuppDelIDs using the Room_ID

			If RoomID1 <> "" and RoomID2 <> "" then
				Set rsGetSDID = createobject("ADODB.Recordset")
				SDSQL = "select * from rooms where room_id = " & RoomID1 & " OR room_id = " & RoomID2
				rsGetSDID.Open SDSQL, db, 3,1

				if rsGetSDID.recordcount = 2 then
					rsGetSDID.movefirst
					SuppDelID1 = rsGetSDID("SuppDelID").value
					rsGetSDID.movenext
					SuppDelID2 = rsGetSDID("SuppDelID").value
				End if
				rsGetSDID.Close
				Set rsGetSDID = Nothing
			End if

			'Now ReInstate the Preference


			DelPrefSQL1 = "update tbl_preferences set Pref_Used = False Where Supplier_Attendee = " &  SuppDelID1 & " AND Supplier_Attendee_Selected = " & SuppDelID2
			DelPrefSQL2 = "update tbl_preferences set Pref_Used = False Where Supplier_Attendee = " &  SuppDelID2 & " AND Supplier_Attendee_Selected = " & SuppDelID1


			db.execute DelPrefSQL1
			db.execute DelPrefSQL2
	'
			'rsGetSDID.Close
			'Set rsGetSDID = Nothing
		End if

but if the user hits cancel i want the code to be skipped.

Chris
 
Ok make a file called popup.asp and put this in it
Code:
<%@LANGUAGE="VBSCRIPT" CODEPAGE="1252"%>
<html>
<head>
<title>Confirm</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>

<body>
<p>Do you wish to remove the preference from the pool?</p>
<%
if request.form("Submit") = "Yes" then
	response.write("Doing your stuff")
	'add your code here
	response.write("<script>self.close()</script>")
elseif request.form("Submit") = "No" then
	response.write("<script>self.close()</script>")
end if
%>
<form action="popup.asp" method="post" name="form1">
  <input type="submit" name="Submit" value="Yes">
  <input type="submit" name="Submit" value="No">
</form>
</body>
</html>
Add the code you pasted where i have put the comment.

then on the page you want to call it from add

Code:
<script language = "Javascript">
	window.open("popup.asp","Confirm","width=300,height=200,resizable=yes,scrollbars=yes,status=no")
</script>
 
Yeah but this is just part of an existing page and I just want to conditionalise this part based on the response to the prompt.

Chris
 
ah.
if there is more than one thing you need to check, could you use tickboxes then at the end submit the form and test the checkboxes.
To do the sql you will have to submit a form at some point or run another page.
Am i missing the point lol?
 
in that case you will need to reload the original page - here is a possible way to do it, modifying your original code:
Code:
<script language="Javascript">

if (confirm("Do you wish to remove the preference from the pool?"))
  document.location.href = document.location.href + "?remove=true";

</script>

<%
If Request.QueryString("remove") = "true" Then
... do the conditional stuff
End if

Tony
_______________________________________________________________
 
By jove I think you've nailed it.. that gives me an idea... As Dave suggests I could stick a check box on the calling form and then pass a querystring parameter.

Thanks chaps, I will give that approach a try.

Chris
 
Ok last question I promise. To check if the checkbox is checked in Jscript is it..

document.getElementById("ChkPool").Checked = True

??

Cheers,

Chris
 
document.getElementById("ChkPool").Checked == True

2 = signs if you are testing a value :)
 
Thanks Dave, I did actually remember that in the code even tho i forgot it in my example.. ;-)

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top