seba070707
Programmer
DIANAL, YOUR EXAMPLE WORKS BUT THE OPTIONS MUST HAVE 'INTERNAL' VALUES AND THEY DON'T.
Is there any way to put the combo information like this...
<option value="USA">United States of America</option>
I suppose that with that modification, the code in the HTML page must be modified too. If it is true, please help me with that thing too.
If you're not DIANAL and want to help me anyway, I will tell you what I posted yesterday...
I POSTED...
-----------------
My question is: CAN I STORE COMBO BOX OPTIONS (AND THEIR VALUES) IN AN EXTERNAL .JS FILE????
In my site, a lot of pages will have the same combo box with the same options and values and I think that it would be better if I store all the combo information in ONE JS file. Because it will be easier to UPDATE in the future.
If it is possible, please tell me how to call the options and values that are stored in the JS file and 'carry' them to the HTML page. Please, make a small example if possible.
DIANAL ANSWERED...
-----------------
========
combo.js
========
combo1 = new Array;
combo2 = new Array;
combo1[0] = "--Select country--";
combo1[1] = "USA";
combo1[2] = "UK";
combo2[0] = "--Select access--";
combo2[1] = "Web access";
combo2[2] = "Email access";
combo2[3] = "FTP access";
// you can extend them as you need
==========
combo.html
==========
<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>
-----------------
Is there any way to put the combo information like this...
<option value="USA">United States of America</option>
I suppose that with that modification, the code in the HTML page must be modified too. If it is true, please help me with that thing too.
If you're not DIANAL and want to help me anyway, I will tell you what I posted yesterday...
I POSTED...
-----------------
My question is: CAN I STORE COMBO BOX OPTIONS (AND THEIR VALUES) IN AN EXTERNAL .JS FILE????
In my site, a lot of pages will have the same combo box with the same options and values and I think that it would be better if I store all the combo information in ONE JS file. Because it will be easier to UPDATE in the future.
If it is possible, please tell me how to call the options and values that are stored in the JS file and 'carry' them to the HTML page. Please, make a small example if possible.
DIANAL ANSWERED...
-----------------
========
combo.js
========
combo1 = new Array;
combo2 = new Array;
combo1[0] = "--Select country--";
combo1[1] = "USA";
combo1[2] = "UK";
combo2[0] = "--Select access--";
combo2[1] = "Web access";
combo2[2] = "Email access";
combo2[3] = "FTP access";
// you can extend them as you need
==========
combo.html
==========
<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>
-----------------