Why doesn't <select> fill onLoad?

I have this situation.

HTML:
<body onLoad="chk_models();">

Open in new window

<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">&nbsp;</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>

Open in new window

Javascript:
function chk_models() {
	if (document.st.ctbrand.value != "") {
		get_mods();
	}
}

Open in new window

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);
	}	
}

Open in new window


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
Richard KortsBusiness Owner / Chief DeveloperAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Leonidas DosasCommented:
Richard you have multiple syntactical errors in your code.I debug your javascript code until one line but you must define what are some variables that you are using as I show you below. I post the code as I debug it and the image with red circle variables that you haven't define these yet:
  <!doctype html>
<html lang="en">
<head>
	<meta charset="UTF-8">
	<title>	</title>
</head>
<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" id="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">&nbsp;</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>
		<script>
		var ctbrand=document.getElementById('ctbrand');
		  function chk_models() {
	            if (ctbrand.value != "") {
		            get_mods();
	            }
              }
			  
			  
			function get_mods() {
			
	if (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');
		ctmodel.remove();		
		sbrand =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);
	}	
}  
		</script>
</body>
</html>

Open in new window



Capture.JPG
0
Richard KortsBusiness Owner / Chief DeveloperAuthor Commented:
Sorry, I forgot to include all the code:

<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']; ?>";
<? } ?>	

Open in new window


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
0
Leonidas DosasCommented:
Put the last code thst you posted it BEFORE my script  and test it. Uncaught ReferenceError: set_pointers is not defined but I think that you defined this function in another part of your script.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Richard KortsBusiness Owner / Chief DeveloperAuthor Commented:
I could not solve it this way, I tried another, it worked.

Points awarded for effort.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
HTML

From novice to tech pro — start learning today.