1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

Help needed for a simple edit

Discussion in 'JavaScript' started by Michael, Jan 31, 2016.

  1. #1
    I do not speak JavaScript and need some help making a small edit to some code.

    I would like to change the format of the output of the script below to be in line and for null values to print "n/a"

    At the moment the format of the output is as a list and null values are just left blank.

    Here is the relevant code as it is.

    First Result:
    <ul></ul>
    Second Result:
    <ul></ul>
    Third Result:
    <ul></ul>
    <script>
    .
    .
    Lots of lines of code here
    .
    .
    //insert Results into the page
    getIPs(function(ip){
    var li = document.createElement("li");
    li.textContent = ip;
    if (some condition here)
    document.getElementsByTagName("ul")[0].appendChild(li);
    else if (another condition here)
    document.getElementsByTagName("ul")[2].appendChild(li);
    else
    document.getElementsByTagName("ul")[1].appendChild(li);
    });
    Code (JavaScript):
    Any help much appreciated....
     
    Michael, Jan 31, 2016 IP
  2. dragonz2444

    dragonz2444 Well-Known Member

    Messages:
    20
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    106
    #2
    Your script is appending to a list html element. If you want the elements to be inline, you can edit the lists CSS to be horizontal which will give make them inline. Another option is to append to another type of html element.

    As for the null element you can just add the below after line 14 of your current code.

    if(!!ip){
    ip = 'n/a';
    } 
    Code (markup):
     
    dragonz2444, Jan 31, 2016 IP
  3. Michael

    Michael Raider

    Messages:
    677
    Likes Received:
    92
    Best Answers:
    0
    Trophy Points:
    150
    #3
    Thank you!
     
    Michael, Feb 1, 2016 IP