Multiple select boxes with same name

mgvenu
mgvenu used Ask the Experts™
on
Hi,

I have a select box as follows

<SELECT name='Offer' size=1 ID='OFFER' onchange="expose(this);">
        <OPTION value='L'>Lease</OPTION>
        <OPTION value='LS'>Lease and Sale</OPTION>
</SELECT>

When I select "Lease" I display a window which has Select box, text box and button the following

<select name="RENT" size=3 multiple ID="LEASE_RATE_PER">
<option value="4">Acre</option>
<option value="1">Month</option>
<option value="3">Sq Ft</option>
<option value="2">Year</option>
</select>

<input type="text" name="year">
<input type="button" name="Accept" value="Accept">

When I select "Lease & Sale" I will have a select box and button.

<select name="RENT" size=3 multiple ID="LEASE_RATE_PER">
<option value="4">Acre</option>
<option value="1">Month</option>
<option value="3">Sq Ft</option>
<option value="2">Year</option>
</select>

<input type="button" name="Accept" value="Accept">

Both the above select boxes Should have the same name.

When I select "Lease", I get a popup window with the above information. I select "Acre" and press accept.

Now again I select "Lease & Sale", I get a popup window as above. Now I select "Month" in the next one and press accept.

Now what is myquestion is I am getting the output value as 4,1.

But I want it to be as "1". The second selected should overwrite the first value.

I am eagerly waiting for the answers.
Any help is greatly appriciated.
venu
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Top Expert 2013

Commented:
You want the second selection to overwrite the first selection.  That is the default behaviour of a select.  What you are getting is the default behaviour of a select multiple.  remove the multiple property from teh select and it will behave the way you want it to.

Cd&

Author

Commented:
Thanks for ur quick reply.
But, I can not remove multiple.
Because I seed to select more than value in a select box.

Assume I am selecting 4,1 from the first select box
and 3,2 from the second select box.

I need the output as 3,2.
But I am getting output as 4,1,3,2.

Author

Commented:
Thanks for ur quick reply.
But, I can not remove multiple.
Because I seed to select more than value in a select box.

Assume I am selecting 4,1 from the first select box
and 3,2 from the second select box.

I need the output as 3,2.
But I am getting output as 4,1,3,2.

Ensure you’re charging the right price for your IT

Do you wonder if your IT business is truly profitable or if you should raise your prices? Learn how to calculate your overhead burden using our free interactive tool and use it to determine the right price for your IT services. Start calculating Now!

Top Expert 2013
Commented:
Then you want one select, not two with the same name.  the contents are identical.  The selects are the same for the browser it is the same entity.  

USe either just one select and the second select will override the first, or give them different names and resolve any conflict with server side processing script.

Cd&
by naming the two select boxes the same you have created a control array which returns a comma delimted value list - as you have experienced ... add a numeral or character to uniquely distinguish each box ...

Author

Commented:
Thanks for ur quick reply.
But, I can not remove multiple.
Because I seed to select more than value in a select box.

Assume I am selecting 4,1 from the first select box
and 3,2 from the second select box.

I need the output as 3,2.
But I am getting output as 4,1,3,2.

Author

Commented:
What do you mean by this??
"add a numeral or character to uniquely distinguish each box"
Can you tell me more
<select name="RENT_1" size=3 multiple ID="LEASE_RATE_PER">
<option value="4">Acre</option>
<option value="1">Month</option>
<option value="3">Sq Ft</option>
<option value="2">Year</option>
</select>

<select name="RENT_2" size=3 multiple ID="LEASE_RATE_PER">
<option value="4">Acre</option>
<option value="1">Month</option>
<option value="3">Sq Ft</option>
<option value="2">Year</option>
</select>


then:

Request.Form("RENT_1") = 1,2
Request.Form("RENT_2") = 3,4
sorry, to follow your example:

then:

Request.Form("RENT_1") = 4,1
Request.Form("RENT_2") = 3,2

Author

Commented:
Sorry I am not looking for this. Is there any way of changing the default behaviour.
just pumping out as many thoughts as i can to help you out:


"...changing the default behaviour..." - not sure what you want to change about it.  You have two boxes with the same name; why? or do you want one box used twice? ...

looking at your original post it seems that the only thing you are trying to do is to display the textbox for the year based on the Lease/Lease & Sale selection - true?

if a user selects Lease, then makes a selection from the Rent select box, clicks accept... the app stores this info, right?

if a user selects Lease, then makes a selection from the Rent select box, the returns to the Offer selection and changes their selection to Lease & Sale - should the Rent box 'lose' the selections already made? or should the additional selections be appended to the currently selected option(s)?

Author

Commented:
I just gave an example code there. It has lot of other things than textbox.

There are some select boxes which are common to both lease and lease&Sale. Apart from these common boxes they have their own textboxes, select boxes etc.

If common boxes [In the above example name="RENT"] are selected in "Lease" and press accept button, I want to show the selected values in both [RENT select box of both "Lease" and Lease&Sale].
Thats why I am using same name for both.

Now my problem is, If user selects "LEASE"
He will be popped with a box RENT select box. He selects values 4,1 and them he goes to "Lease & Sale" and select 3,2 and press accept. Then submit the form.

Now If I go and see in the RENT select boxes, I have all the four values 4,1,3,2 selected.

But I want it as the second one overwrites the first.


Hope you got me.

Thanks for ur replies
venu

Top Expert 2013

Commented:
If you follow good design prctices and use unique name for elements you do not have a problem.  I have seen people write bad code to get around limitations, but writing bad code that creates unnecessary limits is something new.

Cd&
Cd&,

precisely where I was going with this ... was going to try to help the cause be identifying limitations in design... you make a great point:  "but writing bad code that creates unnecessary limits is something new."
I agree with CD about you using bad design practices. However bad this design may be, I may have a bad design solution for you.

When you change between "lease" and "lease and Sale" deselect everything in rent.

basically, in your <SELECT name="offer"> tag, change the onChange Event Handler to
<SELECT name='Offer' size=1 ID='OFFER' onchange="deSelectRent();expose(this);">

and your deSelectRent() function would do the following.

deSelectRent(){
 for(i=0;i<4;i++){
    document.form1.RENT.options[i].selected = false;
}
}


Hope this helps... But I would suggest you change your design practices.

Commented:
How abt listing all the fields that will appear in both pages (just one rent select in this case) in one single page. Hide the fields that belongs to the selection 2 when selection 1 is selected and vice versa. I'm not asking u to use layers here. U can obtain the hidden effect from tables as well.
Top Expert 2013

Commented:
This question has been abandoned. I will make a recommendation to the
moderators on its resolution in a week or two. I appreciate any comments
that would help me to make a recommendation.
<note>
   In the absence of responses, I may recommend DELETE unless it is clear
   to me that it has value as a PAQ.  Silence = you don't care
</note>

Cd&
Top Expert 2013

Commented:
It is time to clean this abandoned question up.

I am putting it on a clean up list for CS.

<recommendation>
points to COBOLdinosaur

</recommendation>

If anyone participating in the Q disagrees with the recommendation,
please leave a comment for the mods.

Cd&
Top Expert 2013

Commented:
Thanks Pasha. :^)

Cd&

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial