seba070707
Programmer
Hello from Argentina!
I am the guy that needed to store COMBO BOX options in an external .JS File.
Please execute the code, and the error will appear. Please try to fix it because I couldn't.
Please, (if it isn't too much trouble), can you change the two one-dimensional arrays and use one two-dimensional array?
THANKS DIANAL !!!!!!
I posted below the code you built...
================
in combo.js file
================
combo1short = new Array;
combo2short = new Array;
combo1 = new Array;
combo2 = new Array;
combo1short[0] = "";
combo1short[1] = "USA";
combo1short[2] = "UK";
combo1[0] = "--Select country--";
combo1[1] = "United States of America";
combo1[2] = "United Kingdom";
combo2short[0] = "";
combo2short[1] = "Web";
combo2short[2] = "Email";
combo2short[3] = "FTP";
combo2[0] = "--Select access--";
combo2[1] = "Web access";
combo2[2] = "Email access";
combo2[3] = "FTP access";
// you could also use two-dimensional array if you like
// i like to use two one-dimensional arrays
==================
in combo.html file
==================
function populate(comboshort,combo, cboname) {
// ... other code
str += "<option value=\"" + comboshort[opt] + "\">"+ combo[opt] + "</option>\n";
// other code
}
// ...
in body:
document.write(populate(combo1short,combo1,"combo1"
);
document.write(populate(combo2short,combo2,"combo2"
);
=========================
HERE IS THE OLD HTML FILE
=========================
<HTML>
<HEAD>
<TITLE> Combo </TITLE>
<script language="JavaScript" src="combo.js"></script>
<script language="JavaScript">
function populate(combo, cboname) {
// combo is array, cboname is string
// return proper string for a combo box
str = "\n"; // \n is for new line
str += "<select name=\"" + cboname + "\">\n"; // \" escapes quotes
for (opt=0; opt<combo.length; opt++) {
str += "<option value=\"" + combo[opt] + "\">"+ combo[opt] + "</option>\n";
}
str += "</select>\n";
return str;
}
function testvalues(frm){
// check to see if the value scan be accessed.
// NS has problems with such function, IE is OK
// frm is the form
for (opt=0; opt < frm.elements.length-2; opt ++) {
// -2 is because I do not want values for buttons
alert(frm.elements[opt].value)
}
}
</script>
</HEAD>
<BODY>
<form name="myForm" method="post" onSubmit="testvalues(this);">
<script language="JavaScript">
document.write(populate(combo1,"combo1"
);
document.write("<br>"
document.write(populate(combo2,"combo2"
);
</script>
<br>
<input type="submit" value="Submit"> <input type="reset" value="Reset">
</form>
</BODY>
</HTML>
====================================================
I am the guy that needed to store COMBO BOX options in an external .JS File.
Please execute the code, and the error will appear. Please try to fix it because I couldn't.
Please, (if it isn't too much trouble), can you change the two one-dimensional arrays and use one two-dimensional array?
THANKS DIANAL !!!!!!
I posted below the code you built...
================
in combo.js file
================
combo1short = new Array;
combo2short = new Array;
combo1 = new Array;
combo2 = new Array;
combo1short[0] = "";
combo1short[1] = "USA";
combo1short[2] = "UK";
combo1[0] = "--Select country--";
combo1[1] = "United States of America";
combo1[2] = "United Kingdom";
combo2short[0] = "";
combo2short[1] = "Web";
combo2short[2] = "Email";
combo2short[3] = "FTP";
combo2[0] = "--Select access--";
combo2[1] = "Web access";
combo2[2] = "Email access";
combo2[3] = "FTP access";
// you could also use two-dimensional array if you like
// i like to use two one-dimensional arrays
==================
in combo.html file
==================
function populate(comboshort,combo, cboname) {
// ... other code
str += "<option value=\"" + comboshort[opt] + "\">"+ combo[opt] + "</option>\n";
// other code
}
// ...
in body:
document.write(populate(combo1short,combo1,"combo1"

document.write(populate(combo2short,combo2,"combo2"

=========================
HERE IS THE OLD HTML FILE
=========================
<HTML>
<HEAD>
<TITLE> Combo </TITLE>
<script language="JavaScript" src="combo.js"></script>
<script language="JavaScript">
function populate(combo, cboname) {
// combo is array, cboname is string
// return proper string for a combo box
str = "\n"; // \n is for new line
str += "<select name=\"" + cboname + "\">\n"; // \" escapes quotes
for (opt=0; opt<combo.length; opt++) {
str += "<option value=\"" + combo[opt] + "\">"+ combo[opt] + "</option>\n";
}
str += "</select>\n";
return str;
}
function testvalues(frm){
// check to see if the value scan be accessed.
// NS has problems with such function, IE is OK
// frm is the form
for (opt=0; opt < frm.elements.length-2; opt ++) {
// -2 is because I do not want values for buttons
alert(frm.elements[opt].value)
}
}
</script>
</HEAD>
<BODY>
<form name="myForm" method="post" onSubmit="testvalues(this);">
<script language="JavaScript">
document.write(populate(combo1,"combo1"

document.write("<br>"

document.write(populate(combo2,"combo2"

</script>
<br>
<input type="submit" value="Submit"> <input type="reset" value="Reset">
</form>
</BODY>
</HTML>
====================================================