473,770 Members | 1,787 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

populate text box from dropdown

I have what I hope is a simple request. I can't really code in javascript, but I am pretty good at cusomizing it with
slight modifications. I code in ASP and HTML.

I am trying to capture customer input of product names to put on custom labels we make. Some of the labels will have our
product names on them, but the customer can add other products that we do not sell.

So, on my product detail page I want a textbox that can have rows copied from values in a dropdown box (containing 700
product ids and names). This is so I can pass the values from the textbox to my ASP script for processing into the
database.

This is how I see it looking:

Dropdown on left, 'COPY' button in middle, Textbox on right.

So you would select a product in the dropdown, click the button and that product would be APPENDED to the textbox,
either before or after the other items already in it. Then the customer would choose another product in the dropdown and
click the button to append it to the list, etc.

The customer will also be allowed to type in other items in the textbox.

Is this do-able? From my sketchy web-search reading, I see that Netscape does not allow copying to clipboard. I don't
think the clipboard would be required, since the source and destination controls are on the same web page, so I believe
javascript can handle it all.

Any responses are greatly appreciated.

Daniel Dillon
Jul 20 '05
20 12437

"Desperado" <de************ *@hotmail.net> wrote in message
news:3d******** *************** *******@news.te ranews.com...

"@SM" <st************ **@wanadoo.fr> wrote in message
news:3F******** *******@wanadoo .fr...

See my other post

It was a beautiful thing.

Thank You


OK, I guess my scripting skills are more rudimentary than I thought.

Your code worked PERFECTLY with one dropdown and one text area, but I am
struggling with adding additional inputs.

Would you be so kind as to paste up that code again, with two different
dropdowns and two different text inputs, so I can see the differences
between things such as ['MyForm']['other'].value and
['MyForm']['other1'].value, and which areas I need to modify to incluse the
additional inputs?

I wouldn't even complain if you commented it :)

Thanks you SO MUCH for your assistance with this.
Jul 20 '05 #11
Thanks Lasse.

It works good.
Then only thing I want to add is a Line feed if Not inserted by the customer, like this...

If (cursor is on a blank line) THEN
out.value += text+"\n";
ELSE
out.value += "\n"+text+" \n";
END IF

Daniel Dillon
Jul 20 '05 #12
"Dannyboyo" <da******@gto.n et> writes:
Then only thing I want to add is a Line feed if Not inserted by the
customer, like this...

I was considering putting it in, but decided to keep it simple :)
If (cursor is on a blank line) THEN
out.value += text+"\n";
ELSE
out.value += "\n"+text+" \n";
END IF


Try:

var val = out.value;
val.replace(/\s*$/,""); // remove terminating whitespace, if any
val += "\n"+text+" \n";
out.value = val;

/L
--
Lasse Reichstein Nielsen - lr*@hotpop.com
DHTML Death Colors: <URL:http://www.infimum.dk/HTML/rasterTriangleD OM.html>
'Faith without judgement merely degrades the spirit divine.'
Jul 20 '05 #13
Thanks again Lasse.

I can't find the correct position for this block of script.
Do I need to remove a line from the original script?

Daniel Dillon
Jul 20 '05 #14

Well, I figured it out. It works, but not as I wish. It causes a blank line to appear between lines of text. I would
like there to be no blank lines. What I am trying to acccomplish with the additional lines of text is to prevent the
user from typing in a line and being unaware that he has to hit 'Enter' before he can choose another from the dropdown.
Below is an example of a customer choosing a few from the dropdown, then typing in 'Daisies' and choosing a couple more
from dropdown. So I only want to cause a line feed if the cursor was left at the end of the word 'Daisies'.

PLANT 056
PLANT 322
PLANT 184
DaisiesPLANT 245
PLANT 821
PLANT 077

I hope this explanation is easy to understand.

Daniel Dillon
Jul 20 '05 #15
In article <_-*************** *****@golden.ne t>, "Dannyboyo" <da******@gto.n et>
writes:
Below is an example of a customer choosing a few from the dropdown, then
typing in 'Daisies' and choosing a couple more
from dropdown. So I only want to cause a line feed if the cursor was left at
the end of the word 'Daisies'.


Instead of commenting it heavily, I chose to use variable names that were
pretty descriptive (if not overly long names) of what they were used for.

This script:

<script type="text/javascript">
function addNextItem(ite mValue,outputDe stination){
formElement = document.forms['myForm'].elements[outputDestinati on]
tempVar = formElement.val ue
if (tempVar.lastIn dexOf("\n") != tempVar.length-1){
tempVar = tempVar + "\n"
}
formElement.val ue = tempVar;
formElement.val ue += itemValue + '\n';
}
</script>

Although I seem to recall that some browsers may use \r or \n\r or \r\n or some
other combination for line breaks in a textarea.

With this HTML:

<form name="myForm" id="myForm">
<select onchange="addNe xtItem(this.val ue,'textOutput1 ')">
<option value="A1">A1</option>
<option value="A2">A2</option>
<option value="A3">A3</option>
<option value="B1">B1</option>
<option value="B2">B2</option>
<option value="B3">B3</option>
<option value="C1">C1</option>
<option value="C2">C2</option>
<option value="C3">C3</option>
</select>
<input type="text" name="textInput 1" size="30">
<input type="button" value="Add It To The List"
onclick="addNex tItem(document. myForm.textInpu t1.value,'textO utput1')">
<textarea name="textOutpu t1" cols="30" rows="10"></textarea>
<br />
<select onchange="addNe xtItem(this.val ue,'textOutput2 ')">
<option value="A1">A1</option>
<option value="A2">A2</option>
<option value="A3">A3</option>
<option value="B1">B1</option>
<option value="B2">B2</option>
<option value="B3">B3</option>
<option value="C1">C1</option>
<option value="C2">C2</option>
<option value="C3">C3</option>
</select>
<input type="text" name="textInput 2" size="30">
<input type="button" value="Add It To The List"
onclick="addNex tItem(document. myForm.textInpu t2.value,'textO utput2')">
<textarea name="textOutpu t2" cols="30" rows="10"></textarea>
</form>

Has several ways to do what you described. Beware of line-wrapping.
Modify as desired.

Tested in IE6, Firebird 0.7 and Opera 7 on a PC. I know, as written, it will
not work in NN4 (NN4 wont pass the value of a select list the way I am passing
it).

If you keep the text input box I used, there needs to be a test to make sure
the value it gets is not a blank value, or you end up with multiple blank
lines. The simplest solution to that is to have a script replace \n\n with \n
upon submission of the form.

Hope this helps.
--
Randy
Jul 20 '05 #16

"HikksNotAtHome " <hi************ @aol.com> wrote in message
news:20******** *************** ****@mb-m25.aol.com...

PERFECT

You ROCK!!!!!

Thanks
Jul 20 '05 #17
Thanks Randy.

This works good - Really good.

I wonder if you can change the code slightly to force the customer to hit a button to add the item from the first
dropdown. I have a dropdown list of about 700 items, so to help navigate the list, I want to give customers a tip to
type the first letter of the item. But with the code the way it is, that adds the first item with that letter to the
textarea.

Thanks for your help.

Daniel Dillon
Jul 20 '05 #18
I think I got it right. I just Cut and Pasted the 'onChange' value to the onClick value of a command button and it works
good for me. Unless there is any risk in that, I am happy with it that way. Thanks Randy and Lasse both.

Daniel Dillon
Jul 20 '05 #19
In article <3v************ ********@golden .net>, "Dannyboyo" <da******@gto.n et>
writes:
Thanks Randy.

This works good - Really good.

I wonder if you can change the code slightly to force the customer to hit a
button to add the item from the first
dropdown. I have a dropdown list of about 700 items, so to help navigate the
list, I want to give customers a tip to
type the first letter of the item. But with the code the way it is, that adds
the first item with that letter to the
textarea.

Thanks for your help.

Daniel Dillon


Remove the onchange from the select, and add a name to it:

<select name="mySelect1 ">

And add a button:

<input type="button" value="Add It To The List"
onclick="addNex tItem(document. myForm.mySelect 1.value,'textOu tput1')">

And now, its still working in modern browsers, and utterly broken in NN4.
Although it didn't work there to begin with (I am too lazy at the moment to
make it work in NN4).
--
Randy
Jul 20 '05 #20

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
3806
by: ziggs | last post by:
I have an asp form that has a text box called "colorBox". Just before text box is the word "Color" that is hyperlinked and will run the color.asp if pressed to show all of the colors in a predetermined 3 character code. Ex., BLU for Blue. Now, what I'd like to do is have the user enter all of the data in the main asp form, ex. Name, address, etc. When they come to the "colorBox", they will be allowed to enter "BLU" by hand or click on...
1
3611
by: jzhang29 | last post by:
I have a JSP page and it contains a dropdown list called Office. What I try to do is: When I select different office from this list, the information of office (address, phone,etc) will be populated in same JSP page. I have a java bean called officeBean that contains all the office information.
0
2442
by: Nithin | last post by:
My code as an txt attachment. I have 2 drop down list boxes that on selection populate text boxes from my database table. I am able to display the correct values in these text boxes. I have 2 questions: 1) I would like the user update these text fields that get populated with data from the database. For some reason I get the error when I change the textbox value.
5
5916
by: Rich | last post by:
Hello, I have a search application to search data in tables in a database (3 sql server tables). I populate 2 comboboxes with with data from each table. One combobox will contain unique CompanyID's. The second combobox will contain unique memberID's. Each of the tables that I have to search contain a CompanyID and a memberID field, and these fields are not unique in the respective tables. Like CompanyID, MemberID
0
1613
by: Kay O'Keeffe | last post by:
Hello, I have written my own custom control and I want one of its properties to display as a dropdown list when clicked, so the user can select from the list, it would be similar to the asp textbox control which has a 'TextMode' property and when clicked on, displays as a dropdown list with 3 values, I want to have a similar type property with a dropdown style.
11
7397
by: eureka | last post by:
Hi All, I'm training in Servlets, JSP and JavaScript, I have a web page in which there's a "StudentName" textbox and below it is a "Names" Dropdown list. Initially the Textbox is empty and the Dropdown doesnt have any items.. The requirement is that as soon as one goes on typing the letters in the StudentName-textbox the corresponding matching names have to appear
0
2773
TonFrere
by: TonFrere | last post by:
Hello, I'm building a windows form application in Visual C# using VS 2005. On my form I need to populate a combobox with Invoices# linked to the current reccord's Order# value. This means that: - The combobox should repopulate if the user changes the value of Order#. - The combobox should repopulate if the user moves through records (using the binding navigator. My problem is that whenever I repopulate the combobox, it's value is reset to...
4
4845
by: olidenia | last post by:
I need some help or tips on the following. I have a .sql database file with the folowing structure: DROP TABLE IF EXISTS `car`; CREATE TABLE IF NOT EXISTS `car` ( `id` int(10) default NULL, `Make` text, `Model` text,
0
9617
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10257
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
10037
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9904
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7456
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6710
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5354
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5482
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
3
2849
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.