Salizar
06-27-2003, 07:30 PM
I found a peice of code that does exactly what I need, unfortunitly its not document very well, and it didn't have an example... So I'm wondering if some more experienced JS users could interpert this code snippet for me...
http://www.faqts.com/knowledge_base...id/2091/fid/178
You can't do this in JavaScript. You'll need a server-side language
like Java (www.javasoft.com), PHP, ASP, ColdFusion or even Perl.
ADDITION AS OF 2-14-02
This is only partially true. If you can generate a page with a server-
side scripting language to create variables or an array of variables
you can include that page through a javascript src.
Example:
Use a server-side scripting language to generate a page which includes
something like this (note: javascript source only)-
var stateAr = new Array();
stateAr[0] = new Array('AK','AK - ALASKA');
stateAr[1] = new Array('AL','AL - ALABAMA');
.
.
.
Then include that generated page with a call like this-
<!--
the src file should use the extention of the scripting
language you used to generate the file. For php use .php
for cold fusion use .cfm, etc
-->
<script src="states.js">
</script>
Then propogate you select list by using the following script-
<script>
function popSelect (){
for(var x = 0; x < stateAr.length; x++){
var opt = new Option(stateAr[x][1], stateAr[x][0]);
//if Netscape 4.x
if(document.layers){
var sel = document.forms.mfrm;
//if IE or Netscape 6
}else{
var sel = document.mfrm;
}
sel.STATE[sel.STATE.length] = opt;
}
}
</script>
What prperties in that code need to be changed to work with the following example?
<!-- JS Array's created by PHP code that gets the Var Name from the Listname colum in the database. -->
<!-- Array Items are proceding row information, excluding NULL's -->
<script type="text/javascript" language='JavaScript'>
tlevel = new Array();
tlevel['0'] = 'tlevel';
tlevel['1'] = 'Standard User';
tlevel['2'] = 'Moderator';
tlevel['3'] = 'Administrator';
tgstat = new Array();
tgstat['0'] = 'tgstat';
tgstat['1'] = 'Pending Member';
tgstat['2'] = 'Full Member';
tgstat['3'] = 'Guild Officer';
tgstat['4'] = 'Guild Leader';
tgstat['5'] = 'Retired Member';
dfont = new Array();
dfont['0'] = 'dfont';
dfont['1'] = 'Normal';
dfont['2'] = 'Normal';
dfont['3'] = 'GuildOfficer';
dfont['4'] = 'GuildLeader';
dfont['5'] = 'Normal';
</script>
<br><br>
<form name="listeditor" method="post">
<table border='1' align='center'>
<tr>
<td>Lists</td><td width='25'> </td><td>Items</td><td>Edit</td>
</tr>
<tr>
<td>
<!-- On click Load the Value array into the dest select box -->
<!-- On Load, open the First array in this List -->
<!-- If changes have been made to the 'DEST' List ask to save changes -->
<!-- These Select Options are automaticly populated by PHP -->
<select name="source" id="source" size="12" onchange="">
<OPTION value='tlevel'>tlevel</OPTION>
<OPTION value='tgstat'>tgstat</OPTION>
<OPTION value='dfont'>dfont</OPTION>
</select>
</td>
<td width='25'>
<!-- Allows movement of the 'DEST' list Array -->
<input type='button' value='move up' title='move selected item up' onclick=""><br /><br>
<input type='button' value='move dn' title='move selected item down' onclick=""><br><br>
</td>
<td>
<select name="dest" id="dest" size="12">
</select>
</td>
<td valign='top'>
<!-- Allow additions to the 'DEST' array -->
Add an Item:<br><input type='text' name='tmp'><br><input type='button' value='<< Add' onclick=''>
</td>
</tr>
<tr>
<!-- Save -- Saves the current active list. Delete -- removes the currently selected item in the 'DEST' List. Prompts for confirmation -->
<td colspan='4' align='center'><input type='button' name='b1' value='Delete' onclick=''><input type='button' name='b1' value='Save' onclick=''></td>
</tr>
</table>
<script>
function popSelect (){
//This is looping through the array.
//How should I change this to the selected array as in my example?
for(var x = 0; x < stateAr.length; x++){
//I'm confused as to what this Option() element does
//I don't understand what he's doing here other than getting the x numbered array element but why two like this...
var opt = new Option(stateAr[x][1], stateAr[x][0]);
//if IE or Netscape 6
//I can safely remove the older broswer support
var sel = document.mfrm;
//What is STATE????
sel.STATE[sel.STATE.length] = opt;
}
}
</script>
http://www.faqts.com/knowledge_base...id/2091/fid/178
You can't do this in JavaScript. You'll need a server-side language
like Java (www.javasoft.com), PHP, ASP, ColdFusion or even Perl.
ADDITION AS OF 2-14-02
This is only partially true. If you can generate a page with a server-
side scripting language to create variables or an array of variables
you can include that page through a javascript src.
Example:
Use a server-side scripting language to generate a page which includes
something like this (note: javascript source only)-
var stateAr = new Array();
stateAr[0] = new Array('AK','AK - ALASKA');
stateAr[1] = new Array('AL','AL - ALABAMA');
.
.
.
Then include that generated page with a call like this-
<!--
the src file should use the extention of the scripting
language you used to generate the file. For php use .php
for cold fusion use .cfm, etc
-->
<script src="states.js">
</script>
Then propogate you select list by using the following script-
<script>
function popSelect (){
for(var x = 0; x < stateAr.length; x++){
var opt = new Option(stateAr[x][1], stateAr[x][0]);
//if Netscape 4.x
if(document.layers){
var sel = document.forms.mfrm;
//if IE or Netscape 6
}else{
var sel = document.mfrm;
}
sel.STATE[sel.STATE.length] = opt;
}
}
</script>
What prperties in that code need to be changed to work with the following example?
<!-- JS Array's created by PHP code that gets the Var Name from the Listname colum in the database. -->
<!-- Array Items are proceding row information, excluding NULL's -->
<script type="text/javascript" language='JavaScript'>
tlevel = new Array();
tlevel['0'] = 'tlevel';
tlevel['1'] = 'Standard User';
tlevel['2'] = 'Moderator';
tlevel['3'] = 'Administrator';
tgstat = new Array();
tgstat['0'] = 'tgstat';
tgstat['1'] = 'Pending Member';
tgstat['2'] = 'Full Member';
tgstat['3'] = 'Guild Officer';
tgstat['4'] = 'Guild Leader';
tgstat['5'] = 'Retired Member';
dfont = new Array();
dfont['0'] = 'dfont';
dfont['1'] = 'Normal';
dfont['2'] = 'Normal';
dfont['3'] = 'GuildOfficer';
dfont['4'] = 'GuildLeader';
dfont['5'] = 'Normal';
</script>
<br><br>
<form name="listeditor" method="post">
<table border='1' align='center'>
<tr>
<td>Lists</td><td width='25'> </td><td>Items</td><td>Edit</td>
</tr>
<tr>
<td>
<!-- On click Load the Value array into the dest select box -->
<!-- On Load, open the First array in this List -->
<!-- If changes have been made to the 'DEST' List ask to save changes -->
<!-- These Select Options are automaticly populated by PHP -->
<select name="source" id="source" size="12" onchange="">
<OPTION value='tlevel'>tlevel</OPTION>
<OPTION value='tgstat'>tgstat</OPTION>
<OPTION value='dfont'>dfont</OPTION>
</select>
</td>
<td width='25'>
<!-- Allows movement of the 'DEST' list Array -->
<input type='button' value='move up' title='move selected item up' onclick=""><br /><br>
<input type='button' value='move dn' title='move selected item down' onclick=""><br><br>
</td>
<td>
<select name="dest" id="dest" size="12">
</select>
</td>
<td valign='top'>
<!-- Allow additions to the 'DEST' array -->
Add an Item:<br><input type='text' name='tmp'><br><input type='button' value='<< Add' onclick=''>
</td>
</tr>
<tr>
<!-- Save -- Saves the current active list. Delete -- removes the currently selected item in the 'DEST' List. Prompts for confirmation -->
<td colspan='4' align='center'><input type='button' name='b1' value='Delete' onclick=''><input type='button' name='b1' value='Save' onclick=''></td>
</tr>
</table>
<script>
function popSelect (){
//This is looping through the array.
//How should I change this to the selected array as in my example?
for(var x = 0; x < stateAr.length; x++){
//I'm confused as to what this Option() element does
//I don't understand what he's doing here other than getting the x numbered array element but why two like this...
var opt = new Option(stateAr[x][1], stateAr[x][0]);
//if IE or Netscape 6
//I can safely remove the older broswer support
var sel = document.mfrm;
//What is STATE????
sel.STATE[sel.STATE.length] = opt;
}
}
</script>