jquery - Change Javascript array to string -


i have following array in javascript

("error", "no name entered", "invalid email", "no message") 

the array can be

("success", "your message has been sent.")     

i create string looks this

<div class="error"> <ul>     <li>no name entered</li>     <li>invalid email</li>     <li>no message</li> </ul> </div> 

the first item in array used div class rest list items,

i've tried using formdata[0], formdata[1], etc. prints undefined if array item doesn't exist.

you can do

var array = ["error", "no name entered", "invalid email", "no message"];  function makediv(array) { var newdiv = '<div class="' + array[0] + '"><ul>';  (var = 1; < array.length; i++) {         newdiv += '<li>' + array[i] + '</li>'; }  newdiv += '</ul></div>';  //append newdiv somewhere  } 

Comments

Popular posts from this blog

blackberry 10 - how to add multiple markers on the google map just by url? -

php - guestbook returning database data to flash -

delphi - Dynamic file type icon -