Avatar of abuyusuf35
abuyusuf35
 asked on

Select Box Always has selected value twice

I have a select box consisting of years and the selected year always appears twice - the select box is being populated from a List of Strings and there are no duplicates in the list the following is an example any idea why the selected year always appears twice

<td align="center">Calendar Year : <img src="public/images/red_arrow_compulsary_field.gif" border="0">
            <select name="selectYear" id="selectYear" style="width:100px" onchange="javascript:onChangeCalendarYear();">
    <option value="-1"
    > 2011</option>
    <option value="1991">1991</option>
    <option value="1992">1992</option>
    <option value="1993">1993</option>
    <option value="1994">1994</option>
    <option value="1995">1995</option>
    <option value="1996">1996</option>
    <option value="1997">1997</option>
    <option value="1998">1998</option>
    <option value="1999">1999</option>
    <option value="2000">2000</option>
    <option value="2001">2001</option>
    <option value="2002">2002</option>
    <option value="2003">2003</option>
    <option value="2004">2004</option>
    <option value="2005">2005</option>
    <option value="2006">2006</option>
    <option value="2007">2007</option>
    <option value="2008">2008</option>
    <option value="2009">2009</option>
    <option value="2010">2010</option>
    <option value="2011">2011</option>
    <option value="2012">2012</option>
    <option value="2013">2013</option>
    <option value="2014">2014</option>
    <option value="2015">2015</option>
    <option value="2016">2016</option>
    <option value="2017">2017</option>
    <option value="2018">2018</option>
    <option value="2019">2019</option>
    <option value="2020">2020</option>
    <option value="2021">2021</option>
    <option value="2022">2022</option>
    <option value="2023">2023</option>
    <option value="2024">2024</option>
    <option value="2025">2025</option>
    <option value="2026">2026</option>
    <option value="2027">2027</option>
    <option value="2028">2028</option>
    <option value="2029">2029</option>
    <option value="2030">2030</option>
    <option value="2031">2031</option>
Java

Avatar of undefined
Last Comment
abuyusuf35

8/22/2022 - Mon
chaitu chaitu

can you show me your script?
CEHJ

Although your code is incomplete, you have the current year in there twice
AielloJ

abuyusuf35:

There is not duplication in your example.  It is how HTML options boxes work.  The <option value="1991"> is the value that will be passed to your script if that option is selected.  The >1991< (brackets show for clarity only) is what's displayed to the user.  In your example the are both the same, but let's use an example of names.  You would want to pass the ID for the name to your script, but display the name to the user.  So that option list would look more like:

    <option value="127">Bob</option>
    <option value="2098">Marie</option>

The ID's (127, 2098) would not make sense to the user, only your script.  The names (Bob, Marie) are what the user sees on the form.  Hope that clears it up.

Regards,

AielloJ
This is the best money I have ever spent. I cannot not tell you how many times these folks have saved my bacon. I learn so much from the contributors.
rwheeler23
abuyusuf35

ASKER
Thanks but that doesn't solve my issue - is there anyway to avoid that  - if a user selects the 2nd 2011 in the drop down the option value passed is invalid and throws an error ?
CEHJ


>>There is not duplication in your example.

Sorry - you're right - i misread the code ;)
ASKER CERTIFIED SOLUTION
chaitu chaitu

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
abuyusuf35

ASKER
That still doesn't solve my problem - for now I have added a header key matching the year selected that solves the '-1' issue - but then the other issue still remains how do I resolve the duplicate 2011 ?
⚡ FREE TRIAL OFFER
Try out a week of full access for free.
Find out why thousands trust the EE community with their toughest problems.
CEHJ

>> any idea why the selected year always appears twice

Appears WHERE twice?
CEHJ

You almost certainly need something like:
<script type="text/javascript">
	    function onChangeCalendarYear(select) {
		var year = select.value;
		if(year > 0) {
		    // You'd really set a form field
		    alert(year);
		}
	    }
</script>
 .....
	      <td align="center">Calendar Year
		  <select name="selectYear" id="selectYear" style="width:100px" onchange="javascript:onChangeCalendarYear(this);">
		      <option value="-1"
		      > Choose year</option>
		      <option value="1991">1991</option>
		      <option value="1992">1992</option>
		      <option value="1993">1993</option>
		      <option value="1994">1994</option>
		      <option value="1995">1995</option>
		      <option value="1996">1996</option>
		      <option value="1997">1997</option>
		      <option value="1998">1998</option>
		      <option value="1999">1999</option>
		      <option value="2000">2000</option>
.....

Open in new window

abuyusuf35

ASKER
I've requested that this question be closed as follows:

Accepted answer: 0 points for abuyusuf35's comment http:/Q_27382778.html#36930670

for the following reason:

none of the suggested solutions resolved my issue
Your help has saved me hundreds of hours of internet surfing.
fblack61
abuyusuf35

ASKER
cancelled