How do i use over for images
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
add a comment |
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
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
add a comment |
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
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
javascript html
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
add a comment |
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
add a comment |
2 Answers
2
active
oldest
votes
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
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 ondom ready
, not before, otherwise the target element isn't avaliable
– Axel Amthor
May 18 '15 at 15:37
add a comment |
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>";
add a comment |
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
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
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
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 ondom ready
, not before, otherwise the target element isn't avaliable
– Axel Amthor
May 18 '15 at 15:37
add a comment |
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
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 ondom ready
, not before, otherwise the target element isn't avaliable
– Axel Amthor
May 18 '15 at 15:37
add a comment |
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
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
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 ondom ready
, not before, otherwise the target element isn't avaliable
– Axel Amthor
May 18 '15 at 15:37
add a comment |
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 ondom 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
add a comment |
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>";
add a comment |
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>";
add a comment |
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>";
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>";
answered May 18 '15 at 14:29
awongawong
12
12
add a comment |
add a comment |
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.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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
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