How do i use over for images












-1















I'm new to javascript and trying new things out. Is it possible to store each of these repeating images in a tr and have 5 separate rows? I currently have a break tag every time the seat reaches 20(19) but i prefer to have it in a row tag. The reason I want it to be in a table is so I can display a number/text under each image so the user knows what the number/text assigned to each image is. I would really appreciate someone's opinions.



My code is per below



<script type="text/javascript">

var x= new Array(100);
var myseat="";
var test="";
var noseats=0;
var seatcounter=0;

function seatgen()
{

for(i=0;i<100;i++)
{
myseat+="<img src='seat_avail.png' onclick='mycheck(this,"+i+")' width='45' height='70'>"; /*alt='seat"+i+"' id='mys"+i+"' onclick='mycheck("+i+")'*/

if( (i+1) % 20 == 0 ){ myseat+="<br>" }

x[i] = "available";
}

document.getElementById("seathere").innerHTML=myseat;
noseats=prompt("How many seats would you like to book","10" );

}


function mycheck(k, p)
{
if( x[p] != "available" ){
alert("Not available");
} else if( seatcounter == noseats ) {
alert("Reacher max seats");
} else {
k.src='seat_select.png';
x[p]="unavailable";
seatcounter+=1;
}
}

</script>









share|improve this question

























  • Is your seatgen function supposed to fill a table of images?

    – Travis Pettry
    May 18 '15 at 14:26











  • Hi Travis, yes that is basically what im trying to do.

    – Tnoz
    May 18 '15 at 14:47
















-1















I'm new to javascript and trying new things out. Is it possible to store each of these repeating images in a tr and have 5 separate rows? I currently have a break tag every time the seat reaches 20(19) but i prefer to have it in a row tag. The reason I want it to be in a table is so I can display a number/text under each image so the user knows what the number/text assigned to each image is. I would really appreciate someone's opinions.



My code is per below



<script type="text/javascript">

var x= new Array(100);
var myseat="";
var test="";
var noseats=0;
var seatcounter=0;

function seatgen()
{

for(i=0;i<100;i++)
{
myseat+="<img src='seat_avail.png' onclick='mycheck(this,"+i+")' width='45' height='70'>"; /*alt='seat"+i+"' id='mys"+i+"' onclick='mycheck("+i+")'*/

if( (i+1) % 20 == 0 ){ myseat+="<br>" }

x[i] = "available";
}

document.getElementById("seathere").innerHTML=myseat;
noseats=prompt("How many seats would you like to book","10" );

}


function mycheck(k, p)
{
if( x[p] != "available" ){
alert("Not available");
} else if( seatcounter == noseats ) {
alert("Reacher max seats");
} else {
k.src='seat_select.png';
x[p]="unavailable";
seatcounter+=1;
}
}

</script>









share|improve this question

























  • Is your seatgen function supposed to fill a table of images?

    – Travis Pettry
    May 18 '15 at 14:26











  • Hi Travis, yes that is basically what im trying to do.

    – Tnoz
    May 18 '15 at 14:47














-1












-1








-1








I'm new to javascript and trying new things out. Is it possible to store each of these repeating images in a tr and have 5 separate rows? I currently have a break tag every time the seat reaches 20(19) but i prefer to have it in a row tag. The reason I want it to be in a table is so I can display a number/text under each image so the user knows what the number/text assigned to each image is. I would really appreciate someone's opinions.



My code is per below



<script type="text/javascript">

var x= new Array(100);
var myseat="";
var test="";
var noseats=0;
var seatcounter=0;

function seatgen()
{

for(i=0;i<100;i++)
{
myseat+="<img src='seat_avail.png' onclick='mycheck(this,"+i+")' width='45' height='70'>"; /*alt='seat"+i+"' id='mys"+i+"' onclick='mycheck("+i+")'*/

if( (i+1) % 20 == 0 ){ myseat+="<br>" }

x[i] = "available";
}

document.getElementById("seathere").innerHTML=myseat;
noseats=prompt("How many seats would you like to book","10" );

}


function mycheck(k, p)
{
if( x[p] != "available" ){
alert("Not available");
} else if( seatcounter == noseats ) {
alert("Reacher max seats");
} else {
k.src='seat_select.png';
x[p]="unavailable";
seatcounter+=1;
}
}

</script>









share|improve this question
















I'm new to javascript and trying new things out. Is it possible to store each of these repeating images in a tr and have 5 separate rows? I currently have a break tag every time the seat reaches 20(19) but i prefer to have it in a row tag. The reason I want it to be in a table is so I can display a number/text under each image so the user knows what the number/text assigned to each image is. I would really appreciate someone's opinions.



My code is per below



<script type="text/javascript">

var x= new Array(100);
var myseat="";
var test="";
var noseats=0;
var seatcounter=0;

function seatgen()
{

for(i=0;i<100;i++)
{
myseat+="<img src='seat_avail.png' onclick='mycheck(this,"+i+")' width='45' height='70'>"; /*alt='seat"+i+"' id='mys"+i+"' onclick='mycheck("+i+")'*/

if( (i+1) % 20 == 0 ){ myseat+="<br>" }

x[i] = "available";
}

document.getElementById("seathere").innerHTML=myseat;
noseats=prompt("How many seats would you like to book","10" );

}


function mycheck(k, p)
{
if( x[p] != "available" ){
alert("Not available");
} else if( seatcounter == noseats ) {
alert("Reacher max seats");
} else {
k.src='seat_select.png';
x[p]="unavailable";
seatcounter+=1;
}
}

</script>






javascript html






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited May 18 '15 at 14:31









DACrosby

8,14132441




8,14132441










asked May 18 '15 at 14:19









TnozTnoz

61




61













  • Is your seatgen function supposed to fill a table of images?

    – Travis Pettry
    May 18 '15 at 14:26











  • Hi Travis, yes that is basically what im trying to do.

    – Tnoz
    May 18 '15 at 14:47



















  • Is your seatgen function supposed to fill a table of images?

    – Travis Pettry
    May 18 '15 at 14:26











  • Hi Travis, yes that is basically what im trying to do.

    – Tnoz
    May 18 '15 at 14:47

















Is your seatgen function supposed to fill a table of images?

– Travis Pettry
May 18 '15 at 14:26





Is your seatgen function supposed to fill a table of images?

– Travis Pettry
May 18 '15 at 14:26













Hi Travis, yes that is basically what im trying to do.

– Tnoz
May 18 '15 at 14:47





Hi Travis, yes that is basically what im trying to do.

– Tnoz
May 18 '15 at 14:47












2 Answers
2






active

oldest

votes


















1














Change to something like:



function seatgen()
{

myseat = "<table><tr>"; // open table and first row

for(i=0;i<100;i++)
{
myseat+="<td><img src='seat_avail.png' onclick='mycheck(this,"+i+")' width='45' height='70'></td>";

if((i+1)%20==0){myseat+="</tr><tr>"} // close row, start new one
x[i]="available";
}

myseat += "</tr></table>"; // close last row and table


This will generate rows with 20 images each, each in a table cell.



Edit: working fiddle here






share|improve this answer


























  • Hi Axel, i've change my script to the above but its currently not displaying anything at all,

    – Tnoz
    May 18 '15 at 15:00











  • You probably need to call the script on dom ready, not before, otherwise the target element isn't avaliable

    – Axel Amthor
    May 18 '15 at 15:37



















0














Each line need to be within block.



myseat+="<table>";
for(i=0;i<100;i++)
{
myseat+="<img src='seat_avail.png' onclick='mycheck(this,"+i+")' width='45' height='70'>";

if((i+1)%20==0){myseat="<tr><td>"+myseat+"</tr></td>"}
x[i]="available";
}

myseat+="</table>";





share|improve this answer























    Your Answer






    StackExchange.ifUsing("editor", function () {
    StackExchange.using("externalEditor", function () {
    StackExchange.using("snippets", function () {
    StackExchange.snippets.init();
    });
    });
    }, "code-snippets");

    StackExchange.ready(function() {
    var channelOptions = {
    tags: "".split(" "),
    id: "1"
    };
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function() {
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled) {
    StackExchange.using("snippets", function() {
    createEditor();
    });
    }
    else {
    createEditor();
    }
    });

    function createEditor() {
    StackExchange.prepareEditor({
    heartbeatType: 'answer',
    autoActivateHeartbeat: false,
    convertImagesToLinks: true,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    bindNavPrevention: true,
    postfix: "",
    imageUploader: {
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    },
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    });


    }
    });














    draft saved

    draft discarded


















    StackExchange.ready(
    function () {
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f30305690%2fhow-do-i-use-tr-tr-over-br-for-images%23new-answer', 'question_page');
    }
    );

    Post as a guest















    Required, but never shown

























    2 Answers
    2






    active

    oldest

    votes








    2 Answers
    2






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    1














    Change to something like:



    function seatgen()
    {

    myseat = "<table><tr>"; // open table and first row

    for(i=0;i<100;i++)
    {
    myseat+="<td><img src='seat_avail.png' onclick='mycheck(this,"+i+")' width='45' height='70'></td>";

    if((i+1)%20==0){myseat+="</tr><tr>"} // close row, start new one
    x[i]="available";
    }

    myseat += "</tr></table>"; // close last row and table


    This will generate rows with 20 images each, each in a table cell.



    Edit: working fiddle here






    share|improve this answer


























    • Hi Axel, i've change my script to the above but its currently not displaying anything at all,

      – Tnoz
      May 18 '15 at 15:00











    • You probably need to call the script on dom ready, not before, otherwise the target element isn't avaliable

      – Axel Amthor
      May 18 '15 at 15:37
















    1














    Change to something like:



    function seatgen()
    {

    myseat = "<table><tr>"; // open table and first row

    for(i=0;i<100;i++)
    {
    myseat+="<td><img src='seat_avail.png' onclick='mycheck(this,"+i+")' width='45' height='70'></td>";

    if((i+1)%20==0){myseat+="</tr><tr>"} // close row, start new one
    x[i]="available";
    }

    myseat += "</tr></table>"; // close last row and table


    This will generate rows with 20 images each, each in a table cell.



    Edit: working fiddle here






    share|improve this answer


























    • Hi Axel, i've change my script to the above but its currently not displaying anything at all,

      – Tnoz
      May 18 '15 at 15:00











    • You probably need to call the script on dom ready, not before, otherwise the target element isn't avaliable

      – Axel Amthor
      May 18 '15 at 15:37














    1












    1








    1







    Change to something like:



    function seatgen()
    {

    myseat = "<table><tr>"; // open table and first row

    for(i=0;i<100;i++)
    {
    myseat+="<td><img src='seat_avail.png' onclick='mycheck(this,"+i+")' width='45' height='70'></td>";

    if((i+1)%20==0){myseat+="</tr><tr>"} // close row, start new one
    x[i]="available";
    }

    myseat += "</tr></table>"; // close last row and table


    This will generate rows with 20 images each, each in a table cell.



    Edit: working fiddle here






    share|improve this answer















    Change to something like:



    function seatgen()
    {

    myseat = "<table><tr>"; // open table and first row

    for(i=0;i<100;i++)
    {
    myseat+="<td><img src='seat_avail.png' onclick='mycheck(this,"+i+")' width='45' height='70'></td>";

    if((i+1)%20==0){myseat+="</tr><tr>"} // close row, start new one
    x[i]="available";
    }

    myseat += "</tr></table>"; // close last row and table


    This will generate rows with 20 images each, each in a table cell.



    Edit: working fiddle here







    share|improve this answer














    share|improve this answer



    share|improve this answer








    edited May 18 '15 at 15:33

























    answered May 18 '15 at 14:26









    Axel AmthorAxel Amthor

    9,61611336




    9,61611336













    • Hi Axel, i've change my script to the above but its currently not displaying anything at all,

      – Tnoz
      May 18 '15 at 15:00











    • You probably need to call the script on dom ready, not before, otherwise the target element isn't avaliable

      – Axel Amthor
      May 18 '15 at 15:37



















    • Hi Axel, i've change my script to the above but its currently not displaying anything at all,

      – Tnoz
      May 18 '15 at 15:00











    • You probably need to call the script on dom ready, not before, otherwise the target element isn't avaliable

      – Axel Amthor
      May 18 '15 at 15:37

















    Hi Axel, i've change my script to the above but its currently not displaying anything at all,

    – Tnoz
    May 18 '15 at 15:00





    Hi Axel, i've change my script to the above but its currently not displaying anything at all,

    – Tnoz
    May 18 '15 at 15:00













    You probably need to call the script on dom ready, not before, otherwise the target element isn't avaliable

    – Axel Amthor
    May 18 '15 at 15:37





    You probably need to call the script on dom ready, not before, otherwise the target element isn't avaliable

    – Axel Amthor
    May 18 '15 at 15:37













    0














    Each line need to be within block.



    myseat+="<table>";
    for(i=0;i<100;i++)
    {
    myseat+="<img src='seat_avail.png' onclick='mycheck(this,"+i+")' width='45' height='70'>";

    if((i+1)%20==0){myseat="<tr><td>"+myseat+"</tr></td>"}
    x[i]="available";
    }

    myseat+="</table>";





    share|improve this answer




























      0














      Each line need to be within block.



      myseat+="<table>";
      for(i=0;i<100;i++)
      {
      myseat+="<img src='seat_avail.png' onclick='mycheck(this,"+i+")' width='45' height='70'>";

      if((i+1)%20==0){myseat="<tr><td>"+myseat+"</tr></td>"}
      x[i]="available";
      }

      myseat+="</table>";





      share|improve this answer


























        0












        0








        0







        Each line need to be within block.



        myseat+="<table>";
        for(i=0;i<100;i++)
        {
        myseat+="<img src='seat_avail.png' onclick='mycheck(this,"+i+")' width='45' height='70'>";

        if((i+1)%20==0){myseat="<tr><td>"+myseat+"</tr></td>"}
        x[i]="available";
        }

        myseat+="</table>";





        share|improve this answer













        Each line need to be within block.



        myseat+="<table>";
        for(i=0;i<100;i++)
        {
        myseat+="<img src='seat_avail.png' onclick='mycheck(this,"+i+")' width='45' height='70'>";

        if((i+1)%20==0){myseat="<tr><td>"+myseat+"</tr></td>"}
        x[i]="available";
        }

        myseat+="</table>";






        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered May 18 '15 at 14:29









        awongawong

        12




        12






























            draft saved

            draft discarded




















































            Thanks for contributing an answer to Stack Overflow!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid



            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.


            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f30305690%2fhow-do-i-use-tr-tr-over-br-for-images%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            這個網誌中的熱門文章

            Tangent Lines Diagram Along Smooth Curve

            Yusuf al-Mu'taman ibn Hud

            Zucchini