Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7191017
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T19:38:22+00:00 2026-05-28T19:38:22+00:00

I am trying to work through how to publish items from multiple arrays while

  • 0

I am trying to work through how to publish items from multiple arrays while first searching through the separate array elements and then return only those items which match a certain criteria. The following code does not do this yet.

enter code here<div id="myDiv">
<script type="text/javascript">


var $ = function(id) {
    return document.getElementBuId(id);

}
var title = new Array("Barbecuing in the Rain","Picnicing in the Arctic",
        "How to Saute on a Radiator", "A Real Grasshopper: Bartending with Insects",
        "Food with a Bullet:  Cooking in Camden", "Mirepoix for Dummies");
var price = new Array(18.50, 23.95, 41.95, 5.95, 13.00, 99.00);
var binding = new Array("Hardcover", "Paperback", "Hardcover", "Paperback", "Paperback", "Hardcover");
var pubYear = new Array(2002, 1975, 2004, 2006, 2001, 1997);
var NYTBestSeller = new Array(true, true, false, false, true, true)
    var seriesTitle = new Array("Food Network", "The Food Network", 
            "Culinary Shortcuts", "Sunset Libations", 
            "Food Network", "The Food Network");
var bargainBooks = ("Food Network Hot Selling Bargain Book");

for (i in title) {
    if (((price[i] <= 25 && binding[i] == "Hardcover") || 
                (price[i] <= 15 && binding[i] == "Softcover")) && (pubYear[i] >= 2000) && 
            (NYTBestSeller[i] == true) && (seriesTitle[i] == "Food Network") || (seriesTitle[i] == "The Food Network"))


        //document.write("<span color='red'>This line is red</span>");



        document.write(title[i] + "<br />");
    document.write(price[i] + "<br />");
    document.write(binding[i] + "<br />");
    document.write(pubYear[i] + "<br />");
    document.write(NYTBestSeller[i] + "<br />");
    document.write(seriesTitle[i] + "<br />" + "<hr/>");

}
</script>

I am searching for books that met a certain criteria and then trying to output where that book is on the page a message of Hot Selling Book in green. But I can’t figure out how to make the document.write work. document.write().style.color=”green” does not work.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-28T19:38:23+00:00Added an answer on May 28, 2026 at 7:38 pm

    document.write output text only, you have to write your own tags there (a div styled as green for example).

    However I suggest you a different approach, what about an empty div with an id and then do the following:

    document.getElementById('your-div-id').innerHTML = 'text <br /> <span style="color: green;">other text</span> and so on';
    

    Will also reorganize code in a better way.

    Document.write will only append code to the end of the output stream (the document in this case), so you can’t specify where output will appear.

    Edit 1:
    Also, what about using objects in this case? As far as I can see, you are using arrays to emulate their behaviour:

    var myObjArray = [
        {
            title: 'mytitle1',
            price: '10$',
            binding: 'dunno',
            pubYear: 'dunno-again',
            NYTBestSeller: true,
            seriesTitle: 'Something'
        },
        {
            ...other object data...
        }
    ]
    
    document.getElementById('your-div-id').innerHTML += myObjArray[0].title + '<br />' + myObjArray[0].price;
    

    Hope you can find it interesting

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to work through the Your first NHibernate based application to get the
I'm trying to work through Project Euler and I'm hitting a barrier on problem
I'm trying to work through the problems on projecteuler.net but I keep running into
I'm trying to work through this guide to Rails routing , but I got
I,m trying to work through and test a Voice Recognition example based on the
Hey all, here is the issue I am currently trying to work through. We
I have been trying to work my way through Project Euler, and have noticed
I'm trying to work my way through Ron Jeffries's Extreme Programming Adventures in C#.
I'm trying to work my way through an Objective-C tutorial. In the book there
I'm trying to work through a problem where I'm mapping EF Entities to POCO

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.