Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Adding OPTION Objects to a SELECT form element in IE5

Posted on 1999-07-14
6
Medium Priority
?
176 Views
Last Modified: 2013-12-25
I've got two fairly standard functions written (one in javascript and on in vbscript) to add options to select form elements. The problem is that in IE5 neither properly assigns the 'value' for the option. The description and the option work otherwise.

Has the 'value' simply been ignored for the option in IE5, is this a bug? can anybody provide an explaination or solution to this?


<SCRIPT language='JavaScript'>

function jvAddToList( objSelect, strText , strValue)
{
   var newopt = new Option(strText);
   newopt.Value = strValue;
   newopt.selected = true;
   objSelect.options[objSelect.options.length] = newopt;
}

</script>


<SCRIPT LANGUAGE=VBScript>

Sub vbAddToList(objLst, strDesc, strVal)
      Dim objElement
   
      Set objElement = document.createElement("OPTION")
      ObjElement.text = strDesc
      ObjElement.value = strVal
   
      objLst.add(objElement)
End Sub

</Script>
0
Comment
Question by:vbWhiz
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 3
6 Comments
 
LVL 9

Expert Comment

by:TTom
ID: 1864058
Don't know if this constitutes an answer, but my reference material says:

"An option object can be created and added to a select object's options[] array, thereby adding a new item to that select field.  To add a new item to "selectName", use the general construction:

document.formName.selectName.options[index] = new Option("textToDisplay", "value", "defaultSelected", "selected")

(NB: "'s in the above construct are MINE)

The latter two options have values of 0 = false or 1 = true.

The JS option seems to be simpler than you are making it; not sure about VBS.  Don't really know why your function would not work, but...

HTH,

Tom
0
 
LVL 3

Author Comment

by:vbWhiz
ID: 1864059
I don't think you completely understand the dilemma. This is code that has been time tested and proven to work (In IE4). I just installed IE5 on my work computer here and suddenly my scripts were exhibiting strange behavior. I traced it to this problem. IE5 doesn't set the value of the option. I'll try the simpler-to-look at method but I have my doubts because these other methods currently don't work in IE5.
0
 
LVL 3

Author Comment

by:vbWhiz
ID: 1864060
Wow...

Wow...

TTom, your suggestion worked. I'm not sure why though...

Anyway go ahead and lock the question to get your well-deserved points!
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.

 
LVL 9

Accepted Solution

by:
TTom earned 400 total points
ID: 1864061
Many and strange are the ways of the vast Internet (and its subjects, particularly IE and NS).

Thanks,

Tom
0
 
LVL 3

Author Comment

by:vbWhiz
ID: 1864062
Yeah, either somebody forgot to write the property let routine for the .value property (I can still retrieve the value, just not set it) or they decided it was no longer important to include.


Either way, including it in the function works great.

Thanks a bunch.

vbWhiz
0
 
LVL 9

Expert Comment

by:TTom
ID: 1864063
Most welcome!

Tom
0

Featured Post

Understanding Linux Permissions

Linux for beginners: How to view the permissions associated with files and directories and also how you can change them.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Color can increase conversions, create feelings of warmth or even incite people to get behind a cause. If you want your website to really impact site visitors, then it is vital to consider the impact color has on them.
When the s#!t hits the fan, you don’t have time to look up who’s on call, draft emails, call collaborators, or send text messages. An instant chat window is definitely the way to go, especially one like HipChat. HipChat is a true business app. An…
This tutorial walks through the best practices in adding a local business to Google Maps including how to properly search for duplicates, marker placement, and inputing business details. Login to your Google Account, then search for "Google Mapmaker…
The viewer will learn how to count occurrences of each item in an array.
Suggested Courses

662 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question