Create an account

Very important

  • To access the important data of the forums, you must be active in each forum and especially in the leaks and database leaks section, send data and after sending the data and activity, data and important content will be opened and visible for you.
  • You will only see chat messages from people who are at or below your level.
  • More than 500,000 database leaks and millions of account leaks are waiting for you, so access and view with more activity.
  • Many important data are inactive and inaccessible for you, so open them with activity. (This will be done automatically)


Thread Rating:
  • 279 Vote(s) - 3.67 Average
  • 1
  • 2
  • 3
  • 4
  • 5
javascript - Getting "Undefined" simple function with loop

#1
So i can't seem to figure this out... The code essentially works, but i get an "undefined" prior to the function running..

var navRender = function indexNav(x,y) {

var mainNav = ["\/", "Inicio","\/abogados-criminales-los-angeles.html", "Defensa Criminal",
"\/delitos-de-drogas-abogados.html", "Delitos de Drogas",
"\/area-de-practica-abogados.html", "Areas de Practica",
"\/abogados-friendman-los-angeles.html", "Abogados Friedman",
"\/contactenos.html", "Contactenos"];

for (i = x; i <= y; i++) {
document.write("<li class=\"pure-menu-item pure-u-1-3\"><a class=\"pure-menu-link href=\"",mainNav[i]);
i++;
document.write("\">", mainNav[i] , "<\/a><\/li>");
};
};

document.getElementById("demo").innerHTML = navRender(0,5);

</script>

Also, i don't know why my "forward slashes are not working either.. i'm escaping with like " \/".. but they still get omitted..

Thanks for the help!
Reply

#2
=> Remove **i++** from for loop.Because it is also plus in for loop.

<!-- begin snippet: js hide: false console: true babel: false -->

<!-- language: lang-js -->


var navRender = function indexNav(x,y) {

var mainNav = ["\/", "Inicio","\/abogados-criminales-los-angeles.html", "Defensa Criminal",
"\/delitos-de-drogas-abogados.html", "Delitos de Drogas",
"\/area-de-practica-abogados.html", "Areas de Practica",
"\/abogados-friendman-los-angeles.html", "Abogados Friedman",
"\/contactenos.html", "Contactenos"];

for (i = x; i <= y; i++)
{
document.write("<li class=\"pure-menu-item pure-u-1-3\"><a class=\"pure-menu-link href=\"",mainNav[i]);
document.write("\">", mainNav[i] , "<\/a><\/li>");
};
};
navRender(0,5);


<!-- end snippet -->
Reply

#3
Here is the right way of doing it.

<!-- begin snippet: js hide: false console: true babel: false -->

<!-- language: lang-js -->

var navRender = function indexNav(x, y) {

var mainNav = ["\/", "Inicio", "\/abogados-criminales-los-angeles.html", "Defensa Criminal", "\/delitos-de-drogas-abogados.html", "Delitos de Drogas", "\/area-de-practica-abogados.html", "Areas de Practica", "\/abogados-friendman-los-angeles.html", "Abogados Friedman", "\/contactenos.html", "Contactenos"];

var html = "";

for (i = x; i <= y; i = i + 2) {
html = html + "<li class='pure-menu-item pure-u-1-3'><a class='pure-menu-link' href='" + mainNav[i] + "'>" + mainNav[i + 1] + "</a></li>";
};

return html;
};
document.getElementById("demo").innerHTML = navRender(0, 5);

<!-- language: lang-html -->

<div id="demo">
</div>

<!-- end snippet -->

Reply

#4


<!-- begin snippet: js hide: false console: true babel: false -->

<!-- language: lang-js -->

var navRender = function indexNav(x,y) {

var mainNav = ["\/", "Inicio", "\/abogados-criminales-los-angeles.html", "Defensa Criminal", "\/delitos-de-drogas-abogados.html", "Delitos de Drogas", "\/area-de-practica-abogados.html", "Areas de Practica", "\/abogados-friendman-los-angeles.html", "Abogados Friedman", "\/contactenos.html", "Contactenos"];

var result = '';
for (var i = x; i <= y; i = i + 2) {
result += '<li class="pure-menu-item pure-u-1-3\">'
result += '<a class="pure-menu-link" href="' + mainNav[i] + '">' + mainNav[i + 1];
result += '</a>';
result += '</li>';
}

return result;
};
document.getElementById("demo").innerHTML = navRender(0,5);

<!-- language: lang-html -->

<ul id="demo"></ul>

<!-- end snippet -->

Reply



Forum Jump:


Users browsing this thread:
1 Guest(s)

©0Day  2016 - 2023 | All Rights Reserved.  Made with    for the community. Connected through