0

Hi am trying to get the textbox value of one asp page to other asp page and set the value here is VBScript which it does

If(disableListHeaderPR()) Then
    bEnablePRField = false
Else
    bEnablePRField = true
End If 

Here disableListHeaderPR() is JS function. I am getting error saying Variable is undefined: 'disableListHeaderPR' Here is the JS function code

function disableListHeaderPR()
{
    if(dateDifference(document.getElementById("txtCommDte").value, "05/04/2012") < 0 ) 
    {
        return false;
    }
    else
    {
        return true;
    } 
}
1
  • 1
    I suppose you know that VBScript is an IE only technology. If you can move all your code to JS, that'll be the best thing to do. Commented Jan 20, 2012 at 15:10

2 Answers 2

2

This page has info on calling vbs from js and vice-versa.

http://www.webdeveloper.com/forum/archive/index.php/t-49920.html

But do keep in mind that as long as you are using VBScript, your app won't run as expected in any browser other than IE.

Sign up to request clarification or add additional context in comments.

1 Comment

This also works in HTAs (which use the Internet Explorer engine) as well as WSF files (WScript/CScript engine). Additionally, this works for ANY installed scripting language.
0

My solution would be to set your variable in the VBScript server-side and then flush the result out to the page in a different JavaScript function that calls your other JavaScript function. Sample (untested) as follows:

<%
    Dim bEnablePRField
    bEnablePRField = Request.Form("checkboxEnablePRField") <> ""
%>
<script type="text/javascript">
    function EnablePRField() {
        if (<%=bEnablePRField%> === 'False') {
            disableListHeaderPR();
        }
    }
    function disableListHeaderPR() {
            if (dateDifference(document.getElementById("txtCommDte").value, "05/04/2012") < 0 ) {
                return false;
            } else {
                return true;
            } 
    }
</script>

Something very similar to that should work for you.

I feel I should point out that, for Classic ASP, the VBScript is only processed server-side so this should work in any browser that supports JavaScript. Before I switched to .Net, I used to pull this trick a lot, and it worked fine in Firefox, as well as IE.

Should you wish instead to use the results of your JavaScript function in your VBScript function, simply store the results of the JavaScript function in a hidden field (e.g., <input id="myResults" name="myResults" type="hidden" />) and then access the value in VBScript (e.g., Request.Form("myResults").

You can also use the hidden field if you are mixing VBScript and JavaScript on the client-side. Just change the way you access the hidden field in VBScript (e.g., document.form("myForm").myResults.value).

Finally, I cannot agree more with techfoobar. If you are mixing VBScript and JavaScript on the client-side, then the only browser it will work in is IE and I would also strongly recommend switching over entirely to JavaScript.

Hope this helps,

Pete

1 Comment

Thanks a lot pete..I will try to do as you suggested.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.