Jump to content

what this line means in JavaScript? Please help

I want to know what actually the below line means. Is it a array or we  are creating an Object.

document.getElementById("status").options[1]=new Option("OPEN","open");

 

I used it for dynamic drop down list

Link to comment
Share on other sites

Link to post
Share on other sites

So the document.getElementById part grabs your dynamic drop down list, I assume you gave it the label "status".

The .option[1] following that gets the Option at the array index '1'

And then the new Option("OPEN","open") is a constructor in javascript that creates a new option with the text "OPEN" and the value "open"


So to sum it up you replaced, or created the option at the array position '1' (remember we count from 0) in your drop down list which will show up as OPEN in your list but it will have the value "open"

Link to comment
Share on other sites

Link to post
Share on other sites

31 minutes ago, Vinod Bahadur Thapa said:

I want to know what actually the below line means. Is it a array or we  are creating an Object.

document.getElementById("status").options[1]=new Option("OPEN","open");

 

I used it for dynamic drop down list

document.getElementById("status").options[1]=new Option("OPEN","open");

document.getElementById("status")    // find the element with the div ID="status"

.options[1]=new Option("OPEN","open"); // will create a new option (in your array) on position 1 (technically position 2, since it starts to 
//count from 0) with the text "OPEN" and the value "open" as a chain.  if there was a variable there, its been replaced by that.

 

~New~  BoomBerryPi project !  ~New~


new build log : http://linustechtips.com/main/topic/533392-build-log-the-scrap-simulator-x/?p=7078757 (5 screen flight sim for 620$ CAD)LTT Web Challenge is back ! go here  :  http://linustechtips.com/main/topic/448184-ltt-web-challenge-3-v21/#entry601004

Link to comment
Share on other sites

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×