Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Onchange event to write value to ASP Variable

Posted on 2009-05-06
5
Medium Priority
?
872 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
5 Comments
 
LVL 12

Accepted Solution

by:
Gibu George earned 1000 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 1000 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

Plesk WordPress Toolkit

Plesk's WordPress Toolkit allows server administrators, resellers and customers to manage their WordPress instances, enabling a variety of development workflows for WordPress admins of all skill levels, from beginners to pros.

See why 2/3 of Plesk servers use it.

Question has a verified solution.

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

Today, the web development industry is booming, and many people consider it to be their vocation. The question you may be asking yourself is – how do I become a web developer?
Dramatic changes are revolutionizing how we build and use technology. Every company is automating, digitizing, and modernizing operations. We need a better, more connected way to work together as teams so we can harness the insights from our system…
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…
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

610 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