Ask a Question related to ASP Database, Design and Development.
-
packet loss #1
Dropdown question (populating a text field)
Hello everybody,
I have a problem and would appreciate any help on offer.
I have a table with two fields in it. On my form there are the following
objects:
Dropdown menu (populated with the first field in the table)
Textfield ( - problem - )
What I'm trying to do is populate the Textfield with the second field
corresponding to the chosen record in the Dropdown menu.
I need to pass on both variables to the next .asp page (which writes the
data into another table) as both need to be written into the database (I'm
using the POST method).
This also needs to be done without reloading the page if at all possible.
e.g.
field1 field2
tom 001
dick 002
harry 003
If "tom" is selected in the Dropdown menu, then i would like to see "001" in
the Textfield etc.
I've found some good code where I found out how I could populate the
Textfield with the Dropdown item itself (using "OnChange" on the Dropdown
menu - callig a small JS function) but this populates the Textfield with the
Dropdown item, and not the corresponding field which I need.
I hope that I've described the problem well enough! Thank you all for
reading.
~p
packet loss Guest
-
populating dropdown using tables from two databases
I tried it with populating the values from the first qury to an array and using that array inside NOT IN clause of second query. But its giving... -
Slow populating dropdown?
I am, for the first time, using Dreamweaver to create recordsets and populate a few dropdowns. Normally, I'd do this by hand, but thought I'd give... -
Populating a Text Field
like i said before the table xtra is perfect for this job, that's what i used previously and it's so much clearer than trying to populate a text... -
dropdown and dynamic text field
hi i am using the following code to try and get a dropdown (sizeList) to fill a dynamic text field with differing values. sizeList has setPrice... -
Populating DropDown in webform
#1) put the data in table AA and put a flag like "New Detail" yes,no and requery you database and if user has selected "New Detail" then add ther... -
Ray at #2
Re: Dropdown question (populating a text field)
The quick and dirty way is to give the values in your dropdown both values
from the db, i.e.
<option value="tom,001">Tom</option>
<option value="dick,002">Dick</option>
And then use client side code to split the values, the get the one after the
comma and use the same type of code that you have seen before to set the
value of the textbox.
Ray at work
"packet loss" <packetloss@gmx.de> wrote in message
news:boef6i$1e1jh0$1@ID-132410.news.uni-berlin.de...in> Hello everybody,
>
> I have a problem and would appreciate any help on offer.
>
> I have a table with two fields in it. On my form there are the following
> objects:
> Dropdown menu (populated with the first field in the table)
> Textfield ( - problem - )
>
> What I'm trying to do is populate the Textfield with the second field
> corresponding to the chosen record in the Dropdown menu.
> I need to pass on both variables to the next .asp page (which writes the
> data into another table) as both need to be written into the database (I'm
> using the POST method).
> This also needs to be done without reloading the page if at all possible.
>
> e.g.
> field1 field2
> tom 001
> dick 002
> harry 003
>
> If "tom" is selected in the Dropdown menu, then i would like to see "001"the> the Textfield etc.
>
> I've found some good code where I found out how I could populate the
> Textfield with the Dropdown item itself (using "OnChange" on the Dropdown
> menu - callig a small JS function) but this populates the Textfield with> Dropdown item, and not the corresponding field which I need.
>
> I hope that I've described the problem well enough! Thank you all for
> reading.
>
> ~p
>
>
>
>
Ray at Guest
-
McKirahan #3
Re: Dropdown question (populating a text field)
"packet loss" <packetloss@gmx.de> wrote in message
news:boef6i$1e1jh0$1@ID-132410.news.uni-berlin.de...in> Hello everybody,
>
> I have a problem and would appreciate any help on offer.
>
> I have a table with two fields in it. On my form there are the following
> objects:
> Dropdown menu (populated with the first field in the table)
> Textfield ( - problem - )
>
> What I'm trying to do is populate the Textfield with the second field
> corresponding to the chosen record in the Dropdown menu.
> I need to pass on both variables to the next .asp page (which writes the
> data into another table) as both need to be written into the database (I'm
> using the POST method).
> This also needs to be done without reloading the page if at all possible.
>
> e.g.
> field1 field2
> tom 001
> dick 002
> harry 003
>
> If "tom" is selected in the Dropdown menu, then i would like to see "001"the> the Textfield etc.
>
> I've found some good code where I found out how I could populate the
> Textfield with the Dropdown item itself (using "OnChange" on the Dropdown
> menu - callig a small JS function) but this populates the Textfield withHow about the following except that you would build the drop-down list from> Dropdown item, and not the corresponding field which I need.
>
> I hope that I've described the problem well enough! Thank you all for
> reading.
>
> ~p
your database.
<html>
<head>
<title>page1.asp</title>
<script language="javascript" type="text/javascript">
<!--
function DropText() {
var form = document.forms[0];
var valu = form.Drop.options[form.Drop.selectedIndex].value;
if (valu != "") form.Text.value = valu;
}
// -->
</script>
</head>
<body>
<form action="page2.asp" method="post">
<select name="Drop" onchange="DropText()">
<option value="">
<option value="001">tom
<option value="002">dick
<option value="003">harry
</select>
<textarea name="Text" rows="6" cols="10"></textarea>
<input type="submit" value="Submit">
</form>
</body>
</html>
McKirahan Guest
-
packet loss #4
Re: Dropdown question (populating a text field)
[...]
from>
> How about the following except that you would build the drop-down listI know why I don't like JS that much lol. I'll look at it tomorrow at work,> your database.
>
>
> <html>
> <head>
> <title>page1.asp</title>
> <script language="javascript" type="text/javascript">
> <!--
> function DropText() {
> var form = document.forms[0];
> var valu = form.Drop.options[form.Drop.selectedIndex].value;
> if (valu != "") form.Text.value = valu;
> }
> // -->
> </script>
> </head>
> <body>
> <form action="page2.asp" method="post">
> <select name="Drop" onchange="DropText()">
> <option value="">
> <option value="001">tom
> <option value="002">dick
> <option value="003">harry
> </select>
> <textarea name="Text" rows="6" cols="10"></textarea>
> <input type="submit" value="Submit">
> </form>
> </body>
> </html>
>
>
It's past 23:00 here and I need my beauty sleep :)
Cheers,
~p
packet loss Guest
-
~p #5
Re: Dropdown question (populating a text field)
[...]
from> How about the following except that you would build the drop-down listHello,> your database.
>
>
> <html>
> <head>
> <title>page1.asp</title>
> <script language="javascript" type="text/javascript">
> <!--
> function DropText() {
> var form = document.forms[0];
> var valu = form.Drop.options[form.Drop.selectedIndex].value;
> if (valu != "") form.Text.value = valu;
> }
> // -->
> </script>
> </head>
> <body>
> <form action="page2.asp" method="post">
> <select name="Drop" onchange="DropText()">
> <option value="">
> <option value="001">tom
> <option value="002">dick
> <option value="003">harry
> </select>
> <textarea name="Text" rows="6" cols="10"></textarea>
> <input type="submit" value="Submit">
> </form>
> </body>
> </html>
>
this works a great! Like you said, all I had to do was to populate the
dropdown box as before, and the other parameter also gets shown (and can be
therefore passed on).
Thank you!
~p
~p Guest
-
McKirahan #6
Re: Dropdown question (populating a text field)
"~p" <packetloss@gmx.de> wrote in message
news:bofnvc$1buupq$1@ID-132410.news.uni-berlin.de...be> [...]> from> > How about the following except that you would build the drop-down list>> > your database.
> >
> >
> > <html>
> > <head>
> > <title>page1.asp</title>
> > <script language="javascript" type="text/javascript">
> > <!--
> > function DropText() {
> > var form = document.forms[0];
> > var valu = form.Drop.options[form.Drop.selectedIndex].value;
> > if (valu != "") form.Text.value = valu;
> > }
> > // -->
> > </script>
> > </head>
> > <body>
> > <form action="page2.asp" method="post">
> > <select name="Drop" onchange="DropText()">
> > <option value="">
> > <option value="001">tom
> > <option value="002">dick
> > <option value="003">harry
> > </select>
> > <textarea name="Text" rows="6" cols="10"></textarea>
> > <input type="submit" value="Submit">
> > </form>
> > </body>
> > </html>
> >
> Hello,
> this works a great! Like you said, all I had to do was to populate the
> dropdown box as before, and the other parameter also gets shown (and canYour very welcome. On reflection, I've thought of a couple of things.> therefore passed on).
>
> Thank you!
>
> ~p
1) There is no need for the "if" test in the function.
2) You might want to give the form a name and reference it in the
function. If there is only one form on the page then there's no problem; if
there's more than one then there could be a problem -- naming it might be
safer.
3) You might want to add "onsubmit=" to the form tag to invoke a function
that ensures that an item has been selected before proceeding to the next
page.
<form action="page2.asp" method="post" name="form1" onsubmit="return
DropTest()">
function DropTest() {
var form = document.form1;
if (form.Text.value != "") return true;
alert("Selection required!");
return false;
}
function DropText() {
var form = document.form1;
var valu = form.Drop.options[form.Drop.selectedIndex].value;
form.Text.value = valu;
}
McKirahan Guest
-
packet loss #7
Re: Dropdown question (populating a text field)
"McKirahan" <News@McKirahan.com> schrieb im Newsbeitrag
news:LkPqb.139977$e01.468311@attbi_s02...if> "~p" <packetloss@gmx.de> wrote in message
> news:bofnvc$1buupq$1@ID-132410.news.uni-berlin.de...> be> > [...]> > from> > > How about the following except that you would build the drop-down list> >> > > your database.
> > >
> > >
> > > <html>
> > > <head>
> > > <title>page1.asp</title>
> > > <script language="javascript" type="text/javascript">
> > > <!--
> > > function DropText() {
> > > var form = document.forms[0];
> > > var valu = form.Drop.options[form.Drop.selectedIndex].value;
> > > if (valu != "") form.Text.value = valu;
> > > }
> > > // -->
> > > </script>
> > > </head>
> > > <body>
> > > <form action="page2.asp" method="post">
> > > <select name="Drop" onchange="DropText()">
> > > <option value="">
> > > <option value="001">tom
> > > <option value="002">dick
> > > <option value="003">harry
> > > </select>
> > > <textarea name="Text" rows="6" cols="10"></textarea>
> > > <input type="submit" value="Submit">
> > > </form>
> > > </body>
> > > </html>
> > >
> > Hello,
> > this works a great! Like you said, all I had to do was to populate the
> > dropdown box as before, and the other parameter also gets shown (and can>> > therefore passed on).
> >
> > Thank you!
> >
> > ~p
> Your very welcome. On reflection, I've thought of a couple of things.
>
> 1) There is no need for the "if" test in the function.
>
> 2) You might want to give the form a name and reference it in the
> function. If there is only one form on the page then there's no problem;function> there's more than one then there could be a problem -- naming it might be
> safer.
>
> 3) You might want to add "onsubmit=" to the form tag to invoke aTo be honest, I didn't see that there was no need for the "if" clause!> that ensures that an item has been selected before proceeding to the next
> page.
>
> <form action="page2.asp" method="post" name="form1" onsubmit="return
> DropTest()">
>
> function DropTest() {
> var form = document.form1;
> if (form.Text.value != "") return true;
> alert("Selection required!");
> return false;
> }
>
> function DropText() {
> var form = document.form1;
> var valu = form.Drop.options[form.Drop.selectedIndex].value;
> form.Text.value = valu;
> }
>
Regarding the second point, I always make a point of giving a form a name,
habit I suppose.
The third point I have handled as well, albeit somewhat different and
probably more complex!
A little background (maybe this will help someone else with a similar
problem) - on the form itself there are 3 objects that require user
input/selection.
1. dropdown (article number)
2. textfield (quantity, default = 1)
3. dropdown (department)
Both dropdowns are populated with data from the db, with the first one also
passing the second corresponding field on as well. These four variables get
carried over and are written into the db along with the time the form was
submitted, and the NT username (which gets spitted up so that the domain
gets removed).
Both dropdowns already have values inserted due to being populated, my
problem was that if a user wanted the first value selected, he would simply
select the quantity a,d the Dept. then submit the form - I got round this by
making sure the first dropdown has focus as the page loads (body
OnLoad-focus) then made sure that a value was selected calling the same
function which you suggested from both an OnBlur and an OnChange in the
dropdown element - this I repeated for all 3 objects and wrote the small
function for each one. Another reason behind this is that after the first
selection, a small text appears like "You wish to enter the following
info..." and the record is then shown in a textfield below the selection.
Once the quantity has been entered/chosen, then that too will then be shown
underneath, ditto the Dept.
Now I'm sure that a lot of people out there are laughing because there are
more elegant ways of doing this - but I'm not that fit with JS - and if
nothing else, it got me writing it a little (even if it was modifying
working code!) If anyone would like the code to take a look at, or suggest
improvements then please let me know - my main aim was for it to work as I
wanted it to and this is now the case - for which I am deeply gratefull!
~p
packet loss Guest



Reply With Quote

