Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

I still can't figure out how to pass JS value to ASP Session 2

Status
Not open for further replies.

riley3

Programmer
Apr 29, 2004
79
US
Hello,
I've been reading Tek-Tips for several days and still can't figure out how to pass a html <select> box selected value to a <input> text box about 10 lines below on the same page. The <select> box is populated from a sql db on page load and after user selection the value is successfully placed in a JS variable (function):

<script language="JavaScript">
function dropdw_text()
{
var w = document.assign.alocdesc.selectedIndex;
var selected_loc = document.assign.alocdesc.options[w].text;
alert(selected_loc);
}
</script>

<select onChange="dropdw_text()" name="alocdesc" id="alocdesc">........</select>

The alert works fine. I just need to get the value of selected_loc into an ASP <%Session("location")%> object and I can't. Can anyone point me in the right direction?
Thanks,
Riley
 
how to pass a html <select> box selected value to a <input> text box about 10 lines below on the same page.
Why would you need to copy the data from a select box into an input box? Why not simply use the select box on it's own?

I just need to get the value of selected_loc into an ASP <%Session("location")%> object
ASP is server-side code; JS (at least, in this instance) is client side. You'll need to call an ASP - either by loading a new page, or using AJAX.


Do you need to do this when the user submits the form? If so, simply do this on the ASP which receives the form's action.

---
Marcus
better questions get better answers - faq581-3339
accessible web design - zioncore.com
 
Thanks for the quick response. The select box is selecting a location name that the end user is familiar with. I need to hold on the location value and use it later on the page to run against the db to pickup an IP number value (the first three pieces) and only allow the end user to enter in the last (4th) piece. At selection time the selected location is only on the client and the server doesn't know what value has been selected. At least I think that's correct. Perhaps there is a different way of doing this and I appreciate any suggestions you may have.
Riley
 
OK, Here's a shot in the dark at your HTML:
Code:
<form action="foo">

  <label for="alocdesc">Select location:</label>
  <select onChange="dropdw_text()" name="alocdesc" id="alocdesc">
    <option value="192.168.2">Accounts</option>
    <option value="192.168.3">Factory</option>
    <option value="192.168.4">Head Office</option>
  </select>
  <br />

  <label for="ip">Choose IP address:</label>
  <input name="network" id="network" disabled="disabled" />
  <input name="ip" id="id" />

And the javascript:
Code:
<script [COLOR=red]type="textjavascript"[/color]>
function dropdw_text()
{
  dropdown = document.getElementById('alocdesc');
  ip = dropdown.options[dropdown.selectedIndex].value;

  inputBox = document.getElementById('network');
  inputBox.value = ip;
}
</script>

This simply takes the 'value' of the dropdown (rather than the text) and copies it to another input box.


I need to hold on the location value and use it later on the page
I'm not sure I understand what you're trying to achieve. You allow the user to choose the location; once the user submits the form, the server will have the location they selected (without having to copy it to an input). The data from dropdowns is sent to the server in exactly the same manner as an input field.

---
Marcus
better questions get better answers - faq581-3339
accessible web design - zioncore.com
 
Sorry for the delay - had to do some chores. Thanks for the reply though. As soon as everyone gets out of here I'm going to work on the code you give me. It's a small IT (equipment & software) inventory system for one of our customers to keep up with their uninstalled and installed stuff (SW & HW). There is a specific IP address range assigned to each location using the 1st 3 decimal places of the IP number. The fourth decimal position is available for use at that location only. We just wanted to minimize errors. When a selection is made from the dropdown form we would like to get the value to the sever so some ASP code would look up the IP address range assigned to that location and put it in 3 of the 4 IP number text boxes farther on down the form on the same page. Thanks again for the help. Riley
 
Thanks very much for the help. This makes it a lot clearer. Riley
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top