Richard Korts
asked on
Why doesn't <select> fill onLoad?
I have this situation.
HTML:
When page displays in browser, only the value "Other" appears in the ctmodel select.
Since the value of ctbrand is NOT other, why does this happen?
Thanks
HTML:
<body onLoad="chk_models();">
<div class="row">
<div class="col-sm-3 col-xs-3"><div style="padding-left:5px;"><u>Select Brand/Model</u></div></div>
<div class="col-sm-3 col-xs-3"> <select name="ctbrand" onChange="get_mods();">
<option value="">-- Select Brand --</option>
<option value="BAC" >BAC</option>
<option value="EVAPCO" selected>EVAPCO</option>
<option value="SPX/MARLEY" >SPX/MARLEY</option>
<option value="Other" >Other</option>
</select>
</div>
<div class="col-sm-1 col-xs-1"> </div>
<div class="col-sm-3 col-xs-3"> <select name="ctmodel" id="ctmodel" onChange="get_dims();">
<option value="">-- Select Model --</option>
</select><br><span style="visibility:hidden;"><input type="text" name="bother" size="14" id="bother"></span>
</div>
</div>
Javascript:function chk_models() {
if (document.st.ctbrand.value != "") {
get_mods();
}
}
function get_mods() {
if (document.st.ctbrand.value == "Other") {
document.getElementById("ctmodel").style.visibility = "hidden";
document.getElementById("bother").style.visibility = "visible";
} else {
document.getElementById("ctmodel").style.visibility = "visible";
document.getElementById("bother").style.visibility = "hidden";
modeld = document.getElementById('ctmodel');
removeOptions(modeld);
sbrand = document.st.ctbrand.value;
var opt = document.createElement('option');
opt.value = "";
opt.innerHTML = "-- Select Model --";
modeld.appendChild(opt);
for (var i = 0; i<=nr; i++){
if (brand[i] == sbrand) {
var opt = document.createElement('option');
opt.value = model[i];
opt.innerHTML = model[i];
modeld.appendChild(opt);
}
}
var opt = document.createElement('option');
opt.value = "Other";
opt.innerHTML = "Other";
modeld.appendChild(opt);
}
}
When page displays in browser, only the value "Other" appears in the ctmodel select.
Since the value of ctbrand is NOT other, why does this happen?
Thanks
ASKER
Sorry, I forgot to include all the code:
This code occurs right after (as you can see) the <script type="text/javascript">
If you are not familiar with php, these values are loaded from a database using php.
If necessary, I can show you the source after php translation.
Thanks
<script type="text/javascript">
window.onload = function () {
set_pointers();
};
brand = new Array();
model = new Array();
leng = new Array();
wid = new Array();
dpt = new Array();
smodel = "<? print $_SESSION['ctmodel']; ?>";
nr = <? print $nr; ?>;
<? for ($i = 0; $i < $nr; $i++) {
$m = mysqli_fetch_array($res,MYSQLI_ASSOC);?>
brand[<? print $i; ?>] = "<? print $m['Brand']; ?>";
model[<? print $i; ?>] = "<? print $m['Model']; ?>";
leng[<? print $i; ?>] = "<? print $m['Length']; ?>";
wid[<? print $i; ?>] = "<? print $m['Width']; ?>";
dpt[<? print $i; ?>] = "<? print $m['Depth']; ?>";
<? } ?>
This code occurs right after (as you can see) the <script type="text/javascript">
If you are not familiar with php, these values are loaded from a database using php.
If necessary, I can show you the source after php translation.
Thanks
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
I could not solve it this way, I tried another, it worked.
Points awarded for effort.
Points awarded for effort.
Open in new window