0

One first page: A form SUBMIT goes to a subsequent page.

VBscript can see the hidden value with ... Request("myName") ...

How do I do the same thing in JavaScript.

 alert(window.location.search);

or

 alert(window.top.location.search.substring(1));

return nothing.

3
  • You're getting data sent in POST method with client-side VBScript? Commented Aug 17, 2013 at 17:02
  • Like you would do for any other POST variable? Commented Aug 17, 2013 at 17:02
  • possible duplicate of How can I get query string values? Commented Aug 17, 2013 at 17:37

3 Answers 3

1

Well, you dont. When you submit a form it sends the values to a server, and the "server-side" reads that in vbscript as Request (Requested). If you want to let the requested value accessible to the Javascript, your server-side (subsequent) page must write that Request data back to the client-side, in other worlds, you have to write the requested value directily in the HTML that will be send back to the client browser.

Ex: In your ASP (Server-Side Subsequent VBScript file) you should write

Response.Write ("<script type=""text/javascript"">alert('" & Request("Data") & "')</script>")
Sign up to request clarification or add additional context in comments.

1 Comment

I agree with you. But I don't know about that Response.Write.
0
<input type='hidden' id='hiddenId'/>

jQuery:

var value = $('#hiddenId').val();
alert(value);

Or

var value = document.getElementById('hiddenId').value;
alert(value);

Comments

0

In your form, you have to have the method set to GET.

<form method="GET" action="somepage">
  <input type=hidden name=myHiddenValue />
</form>

Then on the next page, you can parse the search part of the url with a function like this.

function parseSearch(search, key) {
    search = search.substring(1), items=search.split("&");
    for (var i=0; i<items.length; i++) {
        var item = items[i], parts = item.split("=");
        if (parts[0] === key) {
            return parts[1] || true;
        }
    }
}
parseSearch(location.search, "myHiddenValue"); // returns the hidden value

live demo

2 Comments

Assuming it is a Form and is also a hidden field, for security reasons I will strongly not recommend this kind of solution, I also reinforce to not use such approach once @JoeHall have a server-side VBScript access (not client-side only)
@Roger, yeah there are definitely better solutions, and I should have mentioned that. This is the only way to do it with JavaScript only.

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.