codetoad.com
  ASP Shopping CartForum & BBS
  - all for $20 from CodeToad Plus!
  
  Home || ASP | ASP.Net | C++/C# | DHTML | HTML | Java | Javascript | Perl | VB | XML || CodeToad Plus! || Forums || RAM 
Search Site:
Search Forums:
  selectIndex  dallas72 at 14:49 on Thursday, September 11, 2003
 

I am trying to get the value of a dynamically created select box. The script I am using to get the value is :


<script language = "javascript" >
function extract() {
i=document.RESULT_FORM.TOPIC_TYPE.selectedIndex;
var x = document.RESULT_FORM.TOPIC_TYPE.options.value;
}
</script>

The script I used to create the dynamic select box is :

<select name="TOPIC_TYPE" size="1"
style="background-color:#ffffcc;">
<option>ALL</option>

<SCRIPT Language="JavaScript">
var buildinglist=document.RESULT_FORM.BLDGLIST.value
var bldgarray=buildinglist.split(" ");
var bldglist_counter=document.RESULT_FORM.BLDGLIST_CNT.value

for (var i=0; i < bldglist_counter; i++)
document.write("<OPTION>") +
document.write(bldgarray) +
document.write("</OPTION>");
</SCRIPT>

By using an alert, I am able to see that the selectIndex value for i is correct. but when I use an alert for x, the value is empty. Any suggestions? Thanks!

Bill





<Added>


var x = document.RESULT_FORM.TOPIC_TYPE.options.value;

  Re: selectIndex  Troy Wolf at 18:08 on Thursday, September 11, 2003
 

Simply remove ".options" from this line:
var x = document.RESULT_FORM.TOPIC_TYPE.options.value;


This code shows the working solution.
<script language = "javascript" >
function extract() {
i=document.RESULT_FORM.TOPIC_TYPE.selectedIndex;
alert(i);
var x = document.RESULT_FORM.TOPIC_TYPE.value;
alert(x);
}
</script>
<form name="RESULT_FORM">
<select name="TOPIC_TYPE">
<option value="value 1">Option 1</option>
<option value="value 2">Option 2</option>
<option value="value 3">Option 3</option>
</select>
<p>
<input type=button value="Test" onclick=extract()>
</form>
Troy Wolf: site expert
Shiny Solutions


  Re: selectIndex  dallas72 at 19:50 on Thursday, September 11, 2003
 

Sure enough, your code did work. What I was doing wrong was that I did not define a value for the option tags. I just had <OPTION>option</option>. Thanks for your help!

Oh, thanks for the details on the seminar.

Bill








CodeToad Experts

Can't find the answer?
Our Site experts are answering questions for free in the CodeToad forums








Recent Forum Threads
•  Re: onload event
•  Active Widgets
•  Re: onmouseover change image and text
•  Line Printer Interface
•  import contacts of msn/yahoo
•  Call windows apps from web apps
•  Re: ASP.NET web controls
•  netscape 6 browser problem
•  Re: Print .doc file from the website using System.Diagnostics.Process


Recent Articles
Communicating with the Database (Using ADO)
MagicGrid
Simple Thumbnail Browsing Solution
Type Anywhere
A Better Moustrap: FmtDate to replace FormatDateTime
ASP.NET Forum Source Code
Internal Search Engine
Javascript Growing Window
Simple date validation
Search engine friendly URLs using ASP.NET (C#.NET)


Site Survey
Help us serve you better. Take a five minute survey. Click here!

© Copyright codetoad.com 2001-2005