473,395 Members | 1,521 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

Passing variables between Javascript and Visual Basic

63
When a variable is created using Javascript, should it then be able to be read immediately using embedded VB code or does the submit command have to be entered or are the variables between javascript, visual basic, and vbscript non-interchangable?

I created the following code:

Expand|Select|Wrap|Line Numbers
  1. <script language="javascript">
  2. function question(){
  3.     strReply = confirm('Click Yes if you wish to continue.')
  4.     alert(strreply)
  5. }
  6. </script>
I would then like to take action based on the user response in the VB code.

<%
Test value of strReply and perform code based on the response
%>

The problem is, that although the reply variable can be read with the alert command in the Javascript section, it cannot be read in the VB code. I tried creating a reply input field:

<input id="reply" name="reply" type="text" value="<%=strReply%>"/>

and then in the Javascript section, entering the following command:

document.frmKPIActMaintLoc_01.reply.value = strReply

but it also did not work.
Nov 28 '08 #1
7 17880
acoder
16,027 Expert Mod 8TB
Is this Visual Basic (on the server) or vbscript (client)?

Note that interaction between JavaScript and VBScript will only work in IE. If, however, you mean VB then you should be able to pass it to the server-side script using a form, via the URL, via cookies or via Ajax.

PS. please use [code] tags when posting code. Thanks!
Nov 28 '08 #2
rmurgia
63
Thanks for the response. Do you have a code example of passing the variable between JavaScript and VB. The input field, I gave in my example was within a form and I tried to set the input field within the JavaScript as listed in the example, but I must be missing something, because the variable remained blank.
Nov 28 '08 #3
acoder
16,027 Expert Mod 8TB
If you want VB code to read a JavaScript variable, then you will need to pass that value to the server-side page. You can use a form and submit it, e.g.
Expand|Select|Wrap|Line Numbers
  1. <input type="hidden" id="reply" name="reply" value="">
then in javascript:
Expand|Select|Wrap|Line Numbers
  1. function question(){
  2.     strReply = confirm('Click Yes if you wish to continue.')
  3.     document.getElementById("reply").value = strReply;
  4. }
Now this value will be available on the submitted page once the form is submitted. There are other ways too.
Nov 29 '08 #4
rmurgia
63
acoder,
Thanks for the response. I put in the code in a test page and everything seems to be working. I then changed to VBScript, to use a different message and everthing worked fine. When I moved the code to the actual page where it will be used, it seemed that it is being caught in a loop and keeps asking the question: Do you wish to continue? Are you aware of any quirks when embedding the submit command in the code, when combined with other code, which would cause it to produce and infinite loop. I use an If statement to check if variable strDelRun is set to 1, and within the code, it is set to 2, so it should not be executed the second time. On the test page it seems to work fine.

Thanks for the help,
Ralph

Expand|Select|Wrap|Line Numbers
  1. If strUpdateMode2 = "D" And strDelRun = "1"  Then
  2. %>
  3.     <script language="VBscript">
  4.                 strDelRet = MsgBox("Do you wish to continue? Y/N",68,"KPI Analysis")
  5.                 document.getElementById("DelRet").value = strDelRet
  6.                  document.getElementById("DelRun").value = "2"
  7.             </script> 
  8.  <%           
  9.              strDelRun = "2"  
  10.  %>            
  11.    <script language="JavaScript">
  12.      document.frmKPIActMaintLoc_01.submit()          
  13.    </script>               
  14. <%             
  15. End IF
Nov 30 '08 #5
acoder
16,027 Expert Mod 8TB
It doesn't work quite like that. JavaScript/VBScript is client-side and VB (ASP) is server-side. Once the page has loaded, the server-side code will not change. To effect some change server-side using client-side code, you either need to use Ajax or submit the page.

Can you post all of the code that doesn't work.
Nov 30 '08 #6
rmurgia
63
It's too long to post here. Is there an email address I could send it to?
Dec 2 '08 #7
acoder
16,027 Expert Mod 8TB
Either attach it to your post, post a link to a test page or PM me.
Dec 3 '08 #8

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: Consuelo Guenther | last post by:
Hello, I am having problems with passing variables between pages. I have the following: First asp page has the function: -----------------------------------------------------------------------...
4
by: Familjen Karlsson | last post by:
How will the code under look like in Visual Basic .Net, since you can't use the keyword null anymoore in Visual Basic .Net. What can I use instead. SqlConnection connection = null; SqlCommand...
1
by: Carly | last post by:
Hi, I work in Visual Basic .NET 2002 using ASP.NET. I am wondering what would be the best way to store/pass variables between pages. (Sessions are sooo simple to use but I hear they are not the...
1
by: karthik_c | last post by:
Hi, Anyone know how to pass a value textbox value from a VB6 activex control to vbscript. thanks in advance, karthik
3
by: marknoten | last post by:
I'm quite a newbie to Visual Basic and have a problem with the Input # statement in the Visual Basic Editor from Excel. I would like to read in a tab delimeted text file selected by a user with...
3
by: jsdeveloper | last post by:
Hi, I just started programming in javascript, and I'm having a problem passing variables between javascript and asp code in .asp page. Can you please help? I've given the sample code below. ...
1
by: Ronm | last post by:
Hey Guys, I have a problem which has been driving me crazy for the last days. I'm working on a small project involving: Visual Basic Acces Database ASP and adobe/macromedia Flash,
4
by: BaKo | last post by:
Hey. I was wondering how I would be able to make a variable that has a name that contains another variable. I want to create a bunch of tabpages for files that have names that are like tab_filename....
1
by: tiddwaylll | last post by:
Hi, I have a huge program written in old BASIC. In fact I don't really know what flavour its written in, looks like qbasic I think. I don't need to know what the program does, I just need to...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.