Solved

Onchange event to write value to ASP Variable

Posted on 2009-05-06
5
857 Views
Last Modified: 2012-08-13
I have a simple select form option.  Using the OnChange event I wish to write the selected value into an ASP variable which has been declared earlier.

The ASP variable is: uDisplay

here is the select statement

                 
              <select id="ResultsPerPage" name="ResultsPerPage">
              <option value="10">10</option>
              <option value="20" selected="selected">20</option>
              <option value="50">50</option>
              <option value="100">100</option>
                  </select>
0
Comment
Question by:wobbled
  • 3
5 Comments
 
LVL 12

Accepted Solution

by:
Gibu George earned 250 total points
ID: 24316692
You need to do have this select in a form and then you need to submit the form on submit and get the value from request.

like this
<%
 dim uDisplay=Request("ResultsPerPage");
%>
<form name="form1" action="test.asp" method="POST">
<select id="ResultsPerPage" name="ResultsPerPage" onChange="javascript:document.form1.submit();">
              <option value="10">10</option>
              <option value="20" selected="selected">20</option>
              <option value="50">50</option>
              <option value="100">100</option> 
                  </select>
</form>

Open in new window

0
 
LVL 54

Expert Comment

by:b0lsc0tt
ID: 24319258
wobbled,

The ASP variable isn't there any more.  Once the ASP script is processed the variable is gone.  An exception is server variables but the html page and the onchange event would need to send a request back to the server to modify it.  Javascript is a different language from ASP and runs at a different time (i.e. server vs. clientside).  To do anything in ASP you need ASP script.  The submit option the expert mentioned above could call an ASP page that could then modify the session variable (or a new one).  Another option would be to use AJAX (Javascript code that sends a request to the server WITHOUT refreshing the page).  Keep in mind the basic issue I mentioned at the start though.  Please clarify the type of variable and respond to what I provided if you are interested in details on either method.

Let me know if you have any questions or need more information.

b0lsc0tt
0
 
LVL 54

Assisted Solution

by:b0lsc0tt
b0lsc0tt earned 250 total points
ID: 24319283
wobbled,

By the way ... if you want to avoid server variables and make sure the "declared variable" is sent with the form and that select then have the ASP code write out a hidden form element.  Put the variable's value in that field's value.

Let me know if you have a question.

b0lsc0tt
0
 
LVL 17

Author Closing Comment

by:wobbled
ID: 31578521
Cheers guys thanks for your help on this.  b0lsc0tt  - I have quite a lot of ASP code on the page and depending on what the user selects in the drop down, I wanted to refresh the data on that page then use the selected number to feed into the paging options.  I have decided to go down the hidden form field route you suggested.

Gibu - I have halved the points as you answered the question on how to call a javascript function from onChange.  Thanks
0
 
LVL 54

Expert Comment

by:b0lsc0tt
ID: 24328087
Your welcome!  I'm glad I could help.  Thanks for the grade, the points and the fun question.
bol
p.s.  I have pasted the Grading Comments below since they may be useful to others who view this question.  Right now EE shows them to only the Asker and participants with an Accepted/Assisted comment.

Cheers guys thanks for your help on this. b0lsc0tt - I have quite a lot of ASP code on the page and depending on what the user selects in the drop down, I wanted to refresh the data on that page then use the selected number to feed into the paging options. I have decided to go down the hidden form field route you suggested.
 
Gibu - I have halved the points as you answered the question on how to call a javascript function from onChange. Thanks

Open in new window

0

Featured Post

Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Learn by example how to specify CSS selectors for Selenium WebDriver test automation software.
An enjoyable and seamless user experience can go a long way on an eCommerce site. While a cohesive layout and engaging copy play roles in creating a positive user experience, some sites neglect aspects that seem marginal but in actuality prove very …
This tutorial demonstrates how to identify and create boundary or building outlines in Google Maps. In this example, I outline the boundaries of an enclosed skatepark within a community park.  Login to your Google Account, then  Google for "Google M…
The is a quite short video tutorial. In this video, I'm going to show you how to create self-host WordPress blog with free hosting service.

825 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question