Welcome, Guest: Register On Nairaland / LOGIN! / Trending / Recent / New
Stats: 3,155,127 members, 7,825,532 topics. Date: Sunday, 12 May 2024 at 05:04 PM

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

Nairaland Forum / Science/Technology / Programming / Javascript, Asp And SQL Gurus, Fall Outt! (1009 Views)

ASP.NET MVC [C#] Php Laravel - Training From Scratch-apply now / Simple, Rich & Fast Approach To Learning Javascript. Whatsapp Group Inclusive / Were Can I Download Free Video Tutorials On Javascript Or Ruby (2) (3) (4)

(1) (Reply)

Javascript, Asp And SQL Gurus, Fall Outt! by epospiky(m): 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): 1:26am On Aug 12, 2016
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)

Database Design Expert Needed / Please Where Can I Learn Good Programming And Web Development In Abuja / How To Put Dropdown On My

(Go Up)

Sections: politics (1) business autos (1) jobs (1) career education (1) romance computers phones travel sports fashion health
religion celebs tv-movies music-radio literature webmasters programming techmarket

Links: (1) (2) (3) (4) (5) (6) (7) (8) (9) (10)

Nairaland - Copyright © 2005 - 2024 Oluwaseun Osewa. All rights reserved. See How To Advertise. 13
Disclaimer: Every Nairaland member is solely responsible for anything that he/she posts or uploads on Nairaland.