Solved

Onchange event to write value to ASP Variable

Posted on 2009-05-06
5
853 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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
This article demonstrates how to create a simple responsive confirmation dialog with Ok and Cancel buttons using HTML, CSS, jQuery and Promises
Viewers will get an overview of the benefits and risks of using Bitcoin to accept payments. What Bitcoin is: Legality: Risks: Benefits: Which businesses are best suited?: Other things you should know: How to get started:
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.

771 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now