Question

i have create a drop down called business hour <a onclick ="Businesshour()">BUSINESS HOURS</a> i have a...

i have create a drop down called business hour

<a onclick ="Businesshour()">BUSINESS HOURS</a>

i have a json file

"hours": {
       "Friday": {
           "close": "21:00",
           "open": "11:00"
       },
       "Tuesday": {
           "close": "21:00",
           "open": "11:00"
       },
       "Thursday": {
           "close": "21:00",
           "open": "11:00"
       },
       "Wednesday": {
           "close": "21:00",
           "open": "11:00"
       },
       "Monday": {
           "close": "21:00",
           "open": "11:00"
       }

how do i parse the file using javascript and show the days and time in dropdown

thanks

0 0
Add a comment Improve this question Transcribed image text
Answer #1
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Business Hour</title>
    <style>
        select{
            overflow:auto;
        }
    </style>

</head>
<body>
<a href="" onclick ="Businesshour()">BUSINESS HOURS</a>
<select id="business_hour">

</select>
<script src="script.js"></script>
</body>
</html>

file name:script.js

/**
 * Created by  on 23/3/17.
 */
var obj = {
    "hours": {
        "Friday": {
            "close": "21:00",
            "open": "11:00"
        },
        "Tuesday": {
            "close": "21:00",
            "open": "11:00"
        },
        "Thursday": {
            "close": "21:00",
            "open": "11:00"
        },
        "Wednesday": {
            "close": "21:00",
            "open": "11:00"
        },
        "Monday": {
            "close": "21:00",
            "open": "11:00"
        }
    }
};
function Businesshour() {
    event.preventDefault();
    var select = document.getElementById("business_hour");

    for (key in obj.hours) {
        // alert(key+" "+obj.hours[key]["close"] + " " + obj.hours[key]["open"])
        var option = document.createElement("option");
        option.text = key + " " + obj.hours[key]["close"] + " " + obj.hours[key]["open"];
        select.add(option);
    }
}

output:

BUSINESS HOURS Friday 2100 11:00 Friday 21:00 11:00 Tuesday 21:00 11:00 Thursday 21:00 11:00 Wednesday 21:00 11:00 Monday 21:

Add a comment
Know the answer?
Add Answer to:
i have create a drop down called business hour <a onclick ="Businesshour()">BUSINESS HOURS</a> i have a...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • During his presidential campaing in 2016, Donald Trump said "I know words. I have the best...

    During his presidential campaing in 2016, Donald Trump said "I know words. I have the best words." Let's explore this idea in an objective, scientific manner. Write a function tweets_per_day(jsonurl) that, given the website address (URL) of a JSON file, counts the number of tweets that are sent on every day of the week. Return your result as a dictionary, mapping the day of the week to the total number of tweets sent on that day. For this question, you...

  • So, the brewery selected it’s place and now needs to hire folks. After some testing, they...

    So, the brewery selected it’s place and now needs to hire folks. After some testing, they expect to have approximately 2,000 customers per week. Since they will be open 7 days a week, they need to hire people to help serve their beer. They know that Friday and Saturday will drive sales. Between these 2 days, they will get 50% of their weekly sales. So, Friday has 25% of sales and Saturday has 25% of the sales. As for Sunday...

  • Lab Assignment 4 CIS 2571 Due: 10 Points Create a Java application with the following specifications:...

    Lab Assignment 4 CIS 2571 Due: 10 Points Create a Java application with the following specifications: Your company's IT dept. is creating a schedule for Thanksgiving week. The Thursday is a holiday and therefore no one will be working. There are 3 employees and they have submitted their preferred days to work during that 5-day week ("X" marks the employee's work day): M F Employee # First Name Tu Th 1 Jane X X X Holiday 2 Pablo X Holiday...

  • Customer Distribution by Weekday: A drop-in auto repair shop staffs the same number of mechanics on...

    Customer Distribution by Weekday: A drop-in auto repair shop staffs the same number of mechanics on every weekday (weekends are not counted here). One of the mechanics thinks this is a bad idea because he suspects the number of customers is not evenly distributed across these days. For a sample of 289 customers, the counts by weekday are given in the table. Number of Customers by Day (n = 289)   Monday     Tuesday     Wednesday     Thursday     Friday    Count      43     48     57     75  ...

  • I have this code and need this to be written and applied with an array? How do I process this? Also What would I apply t...

    I have this code and need this to be written and applied with an array? How do I process this? Also What would I apply this with flowchart? Module main()   Call getDailyProfit()   Call calculateWeeklyProfit() Call main() Module getDailyProfit()   // Declare all variables and establish the array          Constant Real SIZE = 7          Declare String days[SIZE] = Sunday, Monday, Tuesday, Thursday. Friday, Saturday          Declare Real days          Declare Real number          Declare Real Index             //Prompt the user for profit information for Sunday          Display “How...

  • I need to create a Java class file and a client file that does the following:  Ask user to enter Today’s date in the fo...

    I need to create a Java class file and a client file that does the following:  Ask user to enter Today’s date in the form (month day year): 2 28 2018  Ask user to enter Birthday in the form (month day year): 11 30 1990  Output the following: The date they were born in the form (year/month/day). The day of the week they were born (Sunday – Saturday). The number of days between their birthday and today’s...

  • You have to make a 90,000,000 payment in Japanese Yen on close of business day, Friday,...

    You have to make a 90,000,000 payment in Japanese Yen on close of business day, Friday, January 18th. You decide to hedge your risk with the futures contracts. Assume you that you enter into the futures position at a close of day on Tuesday, January 15th. Futures and spot data are provided in the file BELOW. Contract size is 12,500,000 yen. Describe the position you decide to enter (long or short). Describe the contract (what month, and what quantity). Document...

  • ​​​​​​​You have to make a 90,000,000 payment in Japanese Yen on close of business day, Friday,...

    ​​​​​​​You have to make a 90,000,000 payment in Japanese Yen on close of business day, Friday, January 17th. You decide to hedge your risk with the futures contracts. Assume you that you enter into the futures position at a close of day on Tuesday, January 14th. Futures and spot data are provided in the file HW1_data.doc. Contract size is 12,500,000 yen. Describe the position you decide to enter (long or short). Describe the contract (what month, and what quantity). Document...

  • Activities Define a struct called Unit containing the following fields I Unit code Unit credit hours...

    Activities Define a struct called Unit containing the following fields I Unit code Unit credit hours Unit semester of study List of prerequisites Number of prerequisites List of post requisites Number of post requisites Inside your main function declare an array of type Unit called units with size 20 elements. This array will contain the information related to all the units in our diploma program. Each of the elements of this array correspond with one our diploma units. II III...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT