Solved

Onchange event to write value to ASP Variable

Posted on 2009-05-06
5
863 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 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

Turn Insights into Action

Communication across every corner of your business is essential to increase the velocity of your application delivery and support pipeline. Automate, standardize, and contextualize your communication processes with xMatters.

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.
This article was originally published on Monitis Blog, you can check it here . Today it’s fairly well known that high-performing websites and applications bring in more visitors, higher SEO, and ultimately more sales. By the same token, downtime…
This video teaches users how to migrate an existing Wordpress website to a new domain.
The viewer will get a basic understanding of what section 508 compliance can entail, learn about skip navigation links, alt text, transcripts, and font size controls.

696 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