This week's book giveaway is in the OCMJEA forum.
We're giving away four copies of OCM Java EE 6 Enterprise Architect Exam Guide and have Paul Allen & Joseph Bambara on-line!
See this thread for details.
The moose likes HTML, CSS and JavaScript and the fly likes read a text file display values in drop down menu Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCM Java EE 6 Enterprise Architect Exam Guide this week in the OCMJEA forum!
JavaRanch » Java Forums » Engineering » HTML, CSS and JavaScript
Bookmark "read a text file display values in drop down menu" Watch "read a text file display values in drop down menu" New topic
Author

read a text file display values in drop down menu

cara dastoli
Greenhorn

Joined: May 22, 2007
Posts: 13
I have two problems. The first one is I am trying to read a text file and display values in a drop down menu on a form. The file is a simple file with fields seperated by commas. I got as far as reading the file, parsing it and displaying the fields in individual text files but I can't figure out how to display them in a drop down.

The second part of my problem is that I can only read and display the values in IE and not Firefox. Any help with the coding on both of these issues is appreciated.

Thanks,

Cara
[ May 22, 2007: Message edited by: cara dastoli ]
Eric Pascarello
author
Rancher

Joined: Nov 08, 2001
Posts: 15376
    
    6
Showing code really helps.

You need to look into

new Option(text,value)

to add the elements to the select.

Eric
cara dastoli
Greenhorn

Joined: May 22, 2007
Posts: 13
Originally posted by Eric Pascarello:
Showing code really helps.

You need to look into

new Option(text,value)

to add the elements to the select.

Eric
cara dastoli
Greenhorn

Joined: May 22, 2007
Posts: 13
Originally posted by Eric Pascarello:
Showing code really helps.

You need to look into

new Option(text,value)

to add the elements to the select.

Eric


Thanks for the info. Here is the original code, it doesn't work with Firefox:


<script language = "javascript">

<!-- Begin/

function GetUni(input)
{
computeForm(input.form);
}


function computeForm(form)
{

objXml = new ActiveXObject("Microsoft.XMLHTTP");

// objXml = new ActiveXObject("Msxml2.XMLHTTP"); older version
var datafile = "myfile.txt";

objXml.open("GET", datafile, true);
objXml.onreadystatechange=function() {
if (objXml.readyState==4) {
display(objXml.responseText);

}
}

objXml.send(null);

function display(msg) {
var t1 = msg;
alert ("test t1: " + t1);
form.outputuni.value = t1;


var string = msg.substring(0,120);
var separator = ',';
var stringArray = string.split(separator);
for (var i=0; i < stringArray.length; i++)
var counter = i + 1;
var v1 = (stringArray[0] + " ");
var v2 = (stringArray[1] + " ");
var v3 = (stringArray[2] + " ");
var v4 = (stringArray[3] + " ");
var v5 = (stringArray[4] + " ");
var v6 = (stringArray[5] + " ");
var v7 = (stringArray[6] + " ");
var v8 = (stringArray[7] + " ");
var v9 = (stringArray[8] + " ");
var v10 = (stringArray[9] + " ");


form.uni1.value = v1;
form.uni2.value = v2;
form.uni3.value = v3;
form.uni4.value = v4;
form.uni5.value = v5;
form.uni6.value = v6;
form.uni7.value = v7;
form.uni8.value = v8;
form.uni9.value = v9;
form.uni10.value = v10;

}

}
// End -->
</script>

<input type="text" size="10" name="uni1"><br>
<input type="text" size="10" name="uni2"><br>
<input type="text" size="10" name="uni4"><br>
<input type="text" size="10" name="uni3"><br>
and so on through "uni10".

I just want these text boxes to be a drop down menu.
Otherwise, it works fine except for the Firefox issue.

Thanks Again.

Cara
Eric Pascarello
author
Rancher

Joined: Nov 08, 2001
Posts: 15376
    
    6
ActiveX = IE only

http://developer.apple.com/internet/webcontent/xmlhttpreq.html

Eric
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: read a text file display values in drop down menu