• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 273
  • Last Modified:

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>
0
abuyusuf35
Asked:
abuyusuf35
  • 4
  • 4
  • 2
  • +1
1 Solution
 
chaitu chaituCommented:
can you show me your script?
0
 
CEHJCommented:
Although your code is incomplete, you have the current year in there twice
0
 
AielloJCommented:
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
0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
abuyusuf35Author Commented:
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 ?
0
 
CEHJCommented:

>>There is not duplication in your example.

Sorry - you're right - i misread the code ;)
0
 
chaitu chaituCommented:

 which value you want to avoid;if u want to avoid 2011;do like this while submitting form
 <select name="selectYear" id="selectYear" style="width:100px" onchange="javascript:onChangeCalendarYear(this);">


 function onChangeCalendarYear(obj)
 {
            if(obj.value !=2011)
            {
                  then only submit the form
            }
 }
0
 
abuyusuf35Author Commented:
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 ?
0
 
CEHJCommented:
>> any idea why the selected year always appears twice

Appears WHERE twice?
0
 
CEHJCommented:
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

0
 
abuyusuf35Author Commented:
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
0
 
abuyusuf35Author Commented:
cancelled
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 4
  • 4
  • 2
  • +1
Tackle projects and never again get stuck behind a technical roadblock.
Join Now