How to take dependent select box option value using javaScript and and do something with it and show it in html document.
im beginner in web development :(
How to take dependent select box option value using javaScript and and do something with it and show it in html document.
im beginner in web development :(
For further actions, you may consider blocking this person and/or reporting abuse
Sarah Thomas -
Vinish Kapoor -
Game Dev Digest - The Newsletter On Unity Game Dev -
Aghilan D.J -
Top comments (6)
What do you mean by "dependent select box option value"? What is it dependent on?
Hello Senpai :)
here i have this container inside this i created two "Divs" with classname "content1" and "content2" , both divs have select box , html code is below...
now here is my Js file....below
so here i want to do if i selected USA it should show USA state names inside second select box option and nothing else(i mean not other country state names) and similar to the other options... and after i selected both values or options when i click to the "Search" button of the web page it should show some details (which i want to show the user) of to that particular state or region ..
You have a variable called
s2
that is both a string and a select box. The same fors1
. It would probably be better to name those things differently to stop your code breaking.e.g.
thank you for your help .. i tried this but its not working...i need to figure out where is the mistake anyways..... do you have telegram/reddit/discord..
i need a mentor.. who can guide me in web development journey.. i started learning javascirpt.. i know little bit html and css
I don't have time to be a mentor, sorry.
You code is quite close. There are a couple of errors. You've fixed the first, i.e. naming the variables.
Next, you have a problem with scope. Variables declared with
let
are scoped to the block they are declared in.In the following:
opArray
is scoped to theif
block, which means outside the block it will not exist.You need to declare
opArray
outside of yourif
blocks, and define it inside, e.g.:Then you have a simple typo. It should be
s2.options.add
nots2.option.add
. option*s*Thank you for your kind help.