Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

DIANAL, THE BROWSER THROWS AN ERROR WITH THE CHANGES YOU DID, help!!

Status
Not open for further replies.

seba070707

Programmer
Joined
Aug 6, 2001
Messages
13
Location
AR
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 += &quot;<option value=\&quot;&quot; + comboshort[opt] + &quot;\&quot;>&quot;+ combo[opt] + &quot;</option>\n&quot;;
// other code
}

// ...

in body:
document.write(populate(combo1short,combo1,&quot;combo1&quot;));
document.write(populate(combo2short,combo2,&quot;combo2&quot;));


=========================
HERE IS THE OLD HTML FILE
=========================


<HTML>
<HEAD>
<TITLE> Combo </TITLE>
<script language=&quot;JavaScript&quot; src=&quot;combo.js&quot;></script>
<script language=&quot;JavaScript&quot;>
function populate(combo, cboname) {
// combo is array, cboname is string
// return proper string for a combo box
str = &quot;\n&quot;; // \n is for new line
str += &quot;<select name=\&quot;&quot; + cboname + &quot;\&quot;>\n&quot;; // \&quot; escapes quotes
for (opt=0; opt<combo.length; opt++) {
str += &quot;<option value=\&quot;&quot; + combo[opt] + &quot;\&quot;>&quot;+ combo[opt] + &quot;</option>\n&quot;;
}
str += &quot;</select>\n&quot;;
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=&quot;myForm&quot; method=&quot;post&quot; onSubmit=&quot;testvalues(this);&quot;>
<script language=&quot;JavaScript&quot;>
document.write(populate(combo1,&quot;combo1&quot;));
document.write(&quot;<br>&quot;)
document.write(populate(combo2,&quot;combo2&quot;));
</script>
<br>
<input type=&quot;submit&quot; value=&quot;Submit&quot;> <input type=&quot;reset&quot; value=&quot;Reset&quot;>
</form>
</BODY>
</HTML>

====================================================
 
I need to know what this is supposed to do if you want me to make it work. -gerrygerry
geraldschafer@hotmail.com
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top