-2

I have always echoed loop incremented variables by using php. Now I want to use the simpler pure javascript.

instead of this:

<script>

<?php

echo "<script>";

for ($i = 1; $i <= 48; $i++) {

echo 'X'.$i;   

echo '}';

echo "</script>";

?>

I just want this:

<script>

for (i = 1; i <= 48; i++) {

document.write (X[i]); //What is the correct syntax for this?

}

</script>
0

1 Answer 1

1

Here is your desired O/P. Concat using '+'.

    
function hello() 
{ 
    for (i = 1; i <= 48; i++) 
    {   document.write ('X'+i); }
}
<!DOCTYPE html>
<html>
<head>
    <title></title>

<script type="text/javascript">

</script>
</head>
<body onload="hello();">
</body>
</html>

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.