|
 |
asp_discuss thread: List Box Dilemma
Message #1 by "Dave Landolin" <dave.landolin@o...> on Fri, 14 Feb 2003 19:58:19
|
|
I have a list box that is being populated with customer names.
There are text boxes on the same page that are meant to contain address
information.
The objective is to populate the text boxes with the address of
the customer that was chosen in the list box.
This would obviuosly need to happen before the page is sent to the
server.
Is this possible?
Any sample code would be appreciated.
Thanks,
DL
Message #2 by Bob Jones <Bob.Jones@t...> on Fri, 14 Feb 2003 14:54:43 -0600
|
|
Of course it's possible. What I'd do is ...
Assumption: the address is multiple fields, it not one big one. I'll use ASP
notation.
Fetch the customer names and address from the DB.
Build a select list of customers.
For every customer record build hidden tags, one for each field of the
address (city, state, zip, etc.) like this:
<input type="hidden" name="city"
value="<%recordsetname.("cityfieldname").value%>">
So, for 10 customers you will have 10 input tags named "city", "state", etc.
NOTE: don't make a <table>. That's a waste of time.
Use JavaScript to make it work together. When the user selects a customer
from the list you can capture the selectedIndex. Now lookup the city, state,
etc. w/ that index! You see, when you name HTML input tags w/ the same name
it acts like an array and you can use array notation to get the correct
address.
So when a customer is selected JavaScript is triggered that grabs the
correct address and populates your on-screen (visible) fields with the
appropriate values.
TaDa!
-----Original Message-----
From: Dave Landolin [mailto:dave.landolin@o...]
Sent: Friday, February 14, 2003 1:58 PM
To: asp_discuss
Subject: [asp_discuss] List Box Dilemma
I have a list box that is being populated with customer names.
There are text boxes on the same page that are meant to contain address
information.
The objective is to populate the text boxes with the address of
the customer that was chosen in the list box.
This would obviuosly need to happen before the page is sent to the
server.
Is this possible?
Any sample code would be appreciated.
Thanks,
DL
Message #3 by "SEAK, Teng-Fong" <tfseak@f...> on Mon, 17 Feb 2003 09:38:42 +0100
|
|
Is this for internal use such as inside a company? If not, please
don't send useless infos such as customs' addresses or details to your
page.
Not only they're useless, and you'll get into trouble concerning
privacy.
Imagine someone looks into the source page. He'll be grateful to you
to
provide him precious infos.
Even if it's not about privacy, you could do like most websites
nowadays:
* add an onchange handler to your first list box and when your user
choose a
customer name, you submit this "partial" form to the server.
* on getting the customer name, the server checks the corresponding
infos
and send back the corresponding infos to form a whole page.
> -----Message d'origine-----
> De : Dave Landolin [mailto:dave.landolin@o...]
> Envoy=C3=A9 : vendredi 14 f=C3=A9vrier 2003 20:58
> =C3=80 : asp_discuss
> Objet : [asp_discuss] List Box Dilemma
>
>
> I have a list box that is being populated with customer names.
> There are text boxes on the same page that are meant to
> contain address
> information.
> The objective is to populate the text boxes with the address of
> the customer that was chosen in the list box.
> This would obviuosly need to happen before the page is sent to the
> server.
> Is this possible?
> Any sample code would be appreciated.
>
> Thanks,
> DL
Message #4 by "Dave Landolin" <dave.landolin@o...> on Wed, 19 Feb 2003 14:38:22
|
|
Bob,
Thanks for the suggestion.
However, I populate my list box with a do loop using vb script:
<%
Do while not rs3.eof
response.write ("<option>")
response.write rs3("customer")
response.write ("</option>")
rs3.movenext
loop
%>
When I incorporate your approach of adding hidden input tags to each
customer I get endless syntax errors. I apologize if this is simple and
I'm just not seeing it. Any further help would be greatly appreciated.
Thanks,
DL
Message #5 by Bob Jones <Bob.Jones@t...> on Wed, 19 Feb 2003 13:41:24 -0600
|
|
OK, here is some code snippets.
NOTES:
See how the single and double quotes are alternated. This allows the
computer to match the pairs properly.
ASSUME the customer names and address are all in the proper order when
fetched from the database.
This code has not been debugged.
Good Luck!
===================================================
do while not rsWhatever.eof
response.write "<input type='hidden' name='city'
value='<%=rsWhatever("city")%>'"
response.write "<input type='hidden' name='street'
value='<%=rsWhatever("street")%>'"
response.write "<input type='hidden' name='zipcode'
value='<%=rsWhatever('zip')%>'"
rsWhatever.movenext
loop
. . .
<form name='myform'>
<select name='customers' onChange='fetchAddress(this.selectedIndex);'>
<option>customer 1</option>
<option>customer 2</option>
. . .
</select>
<input type='text' name='visibleCity' value=''>
<input type='text' name='visibleStreet' value=''>
<input type='text' name='visibleZipCode' value=''>
</form>
<script type='text/javascript'>
function fetchAddress (index) {
document.myform.visibleCity.value = document.myform.city[index].value;
document.myform.visibleStreet.value
document.myform.street[index].value;
document.myform.visibleZipCode.value
document.myform.zipcode[index].value;
}
</script>
-----Original Message-----
From: Dave Landolin [mailto:dave.landolin@o...]
Sent: Wednesday, February 19, 2003 8:38 AM
To: asp_discuss
Subject: [asp_discuss] RE: List Box Dilemma
Bob,
Thanks for the suggestion.
However, I populate my list box with a do loop using vb script:
<%
Do while not rs3.eof
response.write ("<option>")
response.write rs3("customer")
response.write ("</option>")
rs3.movenext
loop
%>
When I incorporate your approach of adding hidden input tags to each
customer I get endless syntax errors. I apologize if this is simple and
I'm just not seeing it. Any further help would be greatly appreciated.
Thanks,
DL
|
|
 |