Dannyboyo a ecrit :
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
You mean a textarea ?
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.
2 soluces :
1) automatic :
==============
<select onchange="nn=th is.options.sele ctedIndex;
(nn==0)? alert('Make an other choice in list') :
this.form['MyTextarea'] += this.options[nn].value+'\n';"
name ... id ... etc >
<option blah blah
<option blah blah
</select>
<textarea name="MyTextare a" id="MyTextarea " rows=8>
2) by force with buttons :
=============== ===========
<html>
<script type="text/javascript"><!--
C = new Array();
function choiceArt(){
chx = document.forms['MyForm']['choicer'];
nn = chx.options.sel ectedIndex;
Article = chx.options[nn].value;
}
function choiceAdd(item) {
if(item=='choic er') {
choiceArt();
C[C.length] = Article;
}
else
C[C.length] = document.forms['MyForm']['other'].value
}
function choiceDel(item) {
if(item=='choic er') {
choiceArt();
for(i=0;i<C.len gth;i++)
if(C[i]==Article) j=i+1*1;
}
else
for(i=0;i<C.len gth;i++)
if(C[i]==document.form s['MyForm']['other'].value)
j=i+1*1;
for(i=j;i<C.len gth;i++)
C[i-1]=C[i];
C.length=(i-1*1);
}
function choiceMem(){
with(document.f orms['MyForm']['Result']) {
value='';
for(i=0;i<C.len gth;i++) {
value += C[i];
if(i<(C.length-1*1)) value += '\n';
}
}
}
function choiceReset() {
C = new Array();
document.forms['MyForm']['Result'].value=' ';
}
// --></script>
<form name="MyForm" id="MyForm" action="p.htm"
onsubmit="alert (this['Result'].value);
// return false;
">
<p><select onchange="nn=th is.options.sele ctedIndex;
if(nn==0) alert('Make an other choice in list');"
name="choicer" id="choicer">
<option selected>Choice an article here
<option value="apples"> Pommes
<option value="bananas" >Bananes
<option value="pears">P oires
</select>
<input type=button onclick="choice Add('choicer'); choiceMem();"
value="Add this article">
<input type=button onclick="choice Del('choicer'); choiceMem();"
value="Delete this article">
<input type=button onclick="choice Reset();"
value="Delette all my choices">
<p>Enter here an other article :
<input type=text name="other" id="other">
<input type=button onclick="choice Add(0);choiceMe m();"
value="Add this new article">
<input type=button onclick="choice Del(0);choiceMe m();"
value="Delete this new article">
<p>That are your choices :
<textarea name="Result" id="Result" rows=12>
</textarea>
<p><input type=submit value="test">
</form>
</html>