-1

HTML:

<div>
<select type="text" id="filterType" class="myInput">
    <option id="one">one</option>
    <option id="two">two</option>
    <option id="three">three</option>
</select>
</div>

JS:

var currentFilterDropDownOpt;
$("#filterType").change(function(){
    currentFilterDropDownOpt = $(this).val();
});

I want to set this currentFilterDropDownOpt to my asp variable.

ASP:

<%
    DIM filterDD
    filterDD = currentFilterDropDownOpt; //something like this
%>

Is there anyone can help?

TIA

1
  • Wrap your drop-down in a <form> that points to the ASP you want to process the value in, make sure the select has a name attribute then call it via that name in the ASP page using Request("select-name-here"). Don't forget the form will need something to trigger the submit, be it a submit button or through code using document.yourform.submit();. Commented Feb 22, 2018 at 21:25

1 Answer 1

0

JS is client-side and ASP is server-side. You cannot transfer a client-side generated variable to your server-side script directly. If you really need to process the variable via ASP, you should send it to the server via an asynchronous request and process the response via JS.

For instance

$("#filterType").change(function(){
  var currentFilterDropDownOpt = $(this).val();
  $.ajax("YOUR_SERVER_LOCATION?currentFilterDropDownOpt="+currentFilterDropDownOpt, {
    success: function(data) {
       //do something with the response
    },
    error: function() {
       //do something if there is an error
    }
  });
});
Sign up to request clarification or add additional context in comments.

5 Comments

can u tell me how to do that?
It can be implemented in a number of different ways. I've added a basic example of how it could be accomplished.
Doesn't have to be AJAX a simple form submit will work just as well. Not to mention if you are going to advocate AJAX calls at least pass them as a POST and not a GET.
@AnthonyL i have tried this but its not working.
@SwatiSingh about as descriptive as your question, “it’s not working” doesn’t help us help you. What happened did it error, what was the error etc...

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.