PDA

View Full Version : Multi selection help


M.a.r.k1
01-05-2003, 10:42 AM
I need help on this little prob.
i have a text input field like this at the first form


<form name=form method=post action="/cgi-bin/your-script.cgi">
quantity: <input type=text name="quantity" size=10> <a href="javascript:choosquantity('quantity', 'opener.document.form.quantity.value', 'DISC');" onMouseOver="window.status='CHOICE';return true;" onMouseOut="window.status='';return true;">CHOICE</a>
</form>


the second form is related to it to put any input and it will insert it in the first form field

function choosmawad(name, output, msg) {
newwin = window.open('','','top=150,left=150,width=325,height=300');
if (!newwin.opener) newwin.opener = self;
with (newwin.document)
{
open();
write('<html>');
write('<body onLoad="document.form.box.focus()"><form name=form>' + msg + '<br>');
write('<p>You may enter your ' + name + ' here and it will be copied into the form for you.');
write('<p><center>' + name + ': <input type=text name=box size=10 onKeyUp=' + output + '=this.value>');
write('<p><input type=button value="Click to close when finished" onClick=window.close()>');
write('</center></form></body></html>');
close();
}


what i want is to change the text input to dropdown list :


<select size=1 name=box onKeyUp=' + output + '=options.selectedIndex><option value=1 selected>1</option><option value=2 selected>2</option></select>


but it wont insert any thing , so if you could help me ... how to chang it from dealing with text input to dropdown select ?

thanks

whammy
01-05-2003, 02:57 PM
Is this form in a popup window?

The basic idea...:

<select name="quantity" onchange="insertQuantity(this.options[this.selectedIndex].value)">
<option value="0">0</option>
<option value="1">1</option>
<option value="2">2</option>
</select>


Now, if your form is in a popup, and the popup is an object, you could just do something like this in the head section (not tested):


function insertQuantity(qty) {
window.newwin ? window.newwin.form1.quantity.value = qty;
}


Not sure exactly what you're doing, but I noticed one thing, you named your form "form", which is not good since that's a reserved word - I doubt that anything will work unless you change that... in my example I used "form1" instead. :)

M.a.r.k1
01-05-2003, 03:36 PM
Thank you whammy,

the script above works fine when its related to a text input field

what i want is :
i have for an example 9 text input fields
3 fields for units | 3 fields for quantity| 3 fields for items

and instade of repeating the same dropdown (which is long list) for every field .. so i want the user to chose from a pop up form and when he chose one and click ok it insert it in the field that he pressed the chose word beside it , and that goes for all the 9 field .

the script i wrote above works fine when the popup form have an input text field and when i wright any thing and click
"Click to close when finished" it insert it in the proper field in the main page, but what i need is to chang this valu :


<input type=text name=box size=10 onKeyUp=' + output + '=this.value>

TO

<select size=1 name=box onKeyUp= ????? here is my problem !!


thank you

glenngv
01-06-2003, 06:42 AM
You dont need onkeyup, you need onchange

function choosmawad(name, output, msg) {
newwin = window.open('','','top=150,left=150,width=325,height=300');
if (!newwin.opener) newwin.opener = self;
with (newwin.document)
{
open();
write('<html>');
write('<body onLoad="document.form1.box.focus()"><form name="form1">' + msg + '<br>');
write('<p>You may enter your ' + name + ' here and it will be copied into the form for you.');
write('<p><center>' + name + ': <select size="1" name="box" onchange="' + output + '=this.options[this.selectedIndex].value">' + '<option value="0">--Choose quantity--</option><option value="1" selected>1</option><option value="2">2</option></select>');
write('<p><input type="button" value="Click to close when finished" onClick="window.close()">');
write('</center></form></body></html>');
close();
}
}

If you noticed, I added a dummy option that says "--Choose quantity--".
If you dont want that, then you should add this line in the onload event:

write('<body onLoad="' + output + '=document.form1.box.options[document.form1.box.selectedIndex].value;document.form1.box.focus()"><form name="form1">' + msg + '<br>');

that is, in order for the selected option to be reflected in the quantity field in the opener window on first load of the popup.

But I'm wondering why do you need the popup when you can just simply do it in the parent window like this:

<form name=form1 method=post action="/cgi-bin/your-script.cgi">
quantity:
<select name="quantity">
<option value="0">0</option>
<option value="1">1</option>
<option value="2">2</option>
</select>
</form>

M.a.r.k1
01-06-2003, 10:54 AM
:thumbsup: Thank you bouth

i made a compenation between your 2 posts and it worked just fine

regard your Q. glenngv

I have many fields that i want the user to chose from a dropdown list only (not to wright any thing) so if i mad a dropdown list for each field ... the page will be about 450 k.b

but with this it will be only 40 kb

best regards to you all for your kind help