Problems with javascript buttons not showing up?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Brian Connelly
    New Member
    • Jan 2011
    • 103

    Problems with javascript buttons not showing up?

    I am working on a script where through a loop buttons are formed with different onClick parameters, but when my html document opens and calls the function, nothing happens. Can some look at the code and tell me what I am obviously doing wrong. Note: I am a beginner and experitmenting to learn.

    My Code:
    Code:
    buttonNames = new Array("Next","Previous","Home");
    function displayButtons{
    for (i=0; i < buttonNames.length; i++)
    <input type="button" value= buttonNames[i]
    for (i in buttonNames)
    	{ 	
    		window.location = new array("next.html","previous.html","home.html");
    		onClick="window.location[i]";
    	}>
    Last edited by Dormilich; Jan 5 '11, 08:43 PM.
  • Dormilich
    Recognized Expert Expert
    • Aug 2008
    • 8694

    #2
    you’re doing pretty much everything wrong.

    - your function definition misses the parameter part (that between the function name and the opening {)
    - bare HTML tags (or parts thereof) are invalid javaScript code
    - events in JavaScript are defined through Event properties/handlers
    - you use a standard for() loop to loop through an array
    - if you define a HTML attribute without quotation marks, the value goes only up to the next whitespace character

    you should definitely read a JavaSript & HTML tutorial, for instance at www.w3schools.com.

    Comment

    Working...