₦airaland Forum

Welcome, Guest: RegisterLoginWith GoogleTrendingRecentNew

Stats: 3,325,102 members, 8,420,341 topics. Date: Thursday, 04 June 2026 at 04:54 PM

Toggle theme

Javascript, Asp And SQL Gurus, Fall Outt! - Programming - Nairaland

Nairaland ForumScience/TechnologyProgrammingJavascript, Asp And SQL Gurus, Fall Outt! (1102 Views)

1 Reply

Javascript, Asp And SQL Gurus, Fall Outt! by epospiky(op): 10:31pm On Aug 11, 2016
Hello there!
I am a web developer - just started learning though. I am presently creating an information system using SQL database. I have built the application in Visual Studio using Asp.net. I have entered some data in my database and I want some of the options or data to come up automatically in a field when I select a particular option from another field. For example, when I run my program and I select car as an option in the VEHICLE field, the BRAND field should be able to generate automatically from the database and allow the user to choose. If I select MOTORCYCLE as the vehicle then different brands of the motorcycle should be able to automatically generate in the BRAND field. There is already a relationship between the two fields and dependency as well. I was meant to understand that it can be achieved using JavaScript but I don't know how. Please anyone with an idea should help me out.
Re: Javascript, Asp And SQL Gurus, Fall Outt! by godofbrowser(m):
epospiky:
Hello there!
I am a web developer - just started learning though. I am presently creating an information system using SQL database. I have built the application in Visual Studio using Asp.net. I have entered some data in my database and I want some of the options or data to come up automatically in a field when I select a particular option from another field. For example, when I run my program and I select car as an option in the VEHICLE field, the BRAND field should be able to generate automatically from the database and allow the user to choose. If I select MOTORCYCLE as the vehicle then different brands of the motorcycle should be able to automatically generate in the BRAND field. There is already a relationship between the two fields and dependency as well. I was meant to understand that it can be achieved using JavaScript but I don't know how. Please anyone with an idea should help me out.
Vanilla javascript



change the selected item to see an example<br>
<select name="vehicles" onchange="display_brands(brands = ['camry','bmw','volvo','benz']);">
<option value="#" label="default" selected> select</option>
<option value="cars" label="cars">cars</option>
<option value="motocycle" label="motocycle">motocycle</option>
<option value="tricycle" label="tricycle">tricycle</option>
</select>

<select name="brands" id="brands" onchange="what you choose to do here depends on you">
<option value="#" label="default" selected> select</option>
</select>

<br>
your database returns an array of brands from the chosen category and then pass it as an argument to the
display brands function.
now assume $brands holds the array, you can parse it through JSON
or whatever you are convenient with

<script>
function display_brands(input) {

var brands = input; //<== brands becomes an array object...then;
document.getElementById('brands').innerHTML = '';
var i;

//Note: for php this would have been a foreach loop
for(i=0; i< brands.length; i++)
{
var output = document.createElement("option"wink;
output.value = brands[i];
output.label = brands[i];
var t = document.createTextNode(brands[i]);
output.appendChild(t);
document.getElementById('brands').appendChild(output);
}
}
</script>

1 Reply

ASP.NET MVC [C#] Php Laravel - Training From Scratch-apply nowSimple, Rich & Fast Approach To Learning Javascript. Whatsapp Group InclusiveWere Can I Download Free Video Tutorials On Javascript Or Ruby234

FUNAAB Hackathon Loading...Malware Invasion On My Laptop, Please HelpEdit My MMM Site