/    Sign up×
Community /Pin to ProfileBookmark

[RESOLVED] Help with content changing in Table

Hello all.

I have a problem with changing the pictures in cells in the javascript created table.
I need to change the picture in specific cells. Like: 5.th row, 4.th cell and so on.

Here is the code:

[CODE]
<!DOCTYPE html PUBLIC “-//W3C//DTD XHTML 1.0 Transitional//EN” “http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd”>
<html xmlns=”http://www.w3.org/1999/xhtml”>
<title>Untitled Document</title>
<script language=”JavaScript” type=”text/javascript”>

function createfield()
{
var hosz_val = document.Jatektermeretek.hosz.value;
var szel_val = document.Jatektermeretek.szél.value;
var body= document.getElementsByTagName(“body”) [0];
var jatekter= document.createElement(“table”);
var jatekter_body = document.createElement(“tbody”);

for (var j=0; j< hosz_val; j++)
{
var sor= document.createElement(“tr”);

for (var i=0; i< szel_val; i++)
{
var cella= document.createElement(“td”);
cellaimg= document.createElement(“img”);
cellaimg.setAttribute(“src”,”../pics/houdini_pics/field_bgimg.png”);
cella.appendChild(cellaimg);
sor.appendChild(cella);
}
jatekter_body.appendChild(sor);
jatekter.appendChild(jatekter_body);
}
body.appendChild(jatekter);
jatekter.setAttribute(“border”,”0″);
jatekter.setAttribute(“align”, “center”);
jatekter.setAttribute(“cellPadding”, “0”);
jatekter.setAttribute(“celling”, “0”);

var x=document.getElementsByTagName(“td”);
alert(x.length);
x[21].setAttribute(“”)
}
function numcheck()
{
var hosz_val = document.Jatektermeretek.hosz.value;
var szel_val = document.Jatektermeretek.szél.value;
if (hosz_val < 5 || szel_val < 5)
{
alert(“A megadott értékek túl alacsonyak, a játék nem kivitelezheto” + ‘n’ + “Ne feledje: A több néha jobb”);
}
else
{
createfield();
}
}
</script>
<div align=”center”>
<h1><span class=”style1″>Els&#337; Javascript beadand&oacute;</span></h1>
<h2>Houdini Kalapja</h2>
</div>
<h3 align=”left”>J&aacute;t&eacute;kszab&aacute;ly:</h3>
<blockquote><p align=”left”><strong>1.:</strong> Adja meg a j&aacute;t&eacute;kt&eacute;r m&eacute;reteit.<br />
<strong>2.:</strong> A fel, le , jobbra, balra gombokkal a kalapot mozgatva el kell kapni a nyulat.<br />
<strong>3.:</strong> A kalap mozgat&aacute;s k&ouml;zben forog, a ny&uacute;lra <strong>r&aacute; kell h&uacute;zni</strong> a kalapot! <br />
<strong>4.:</strong> A j&aacute;t&eacute;k akkor &eacute;r v&eacute;get sikeresen, ha r&aacute;tett&uuml;k a ny&uacute;lra a kalapot. </p>
</blockquote>
<br />
<br />
<form action=”” method=”get” name=”Jatektermeretek” id=”meretek”>
<div align=”left”>
<blockquote>
<p>Adja meg a játéktér méreteit:
<input name=”hosz” type=”text” value=”0″ size=”4″ maxlength=”2″ />
X
<input name=”sz&eacute;l” type=”text” value=”0″ size=”4″ maxlength=”2″ />
&nbsp;&nbsp;<input name=”submit” type=”button” value=”Indul” onclick=”numcheck()” />
</p>
<p>&nbsp;</p>
</blockquote>
</div>
</form>
</html>[/CODE]

to post a comment
JavaScript

9 Comments(s)

Copy linkTweet thisAlerts:
@TileaNov 04.2011 — Do you want to change the image depending on a certain action from the user?
Copy linkTweet thisAlerts:
@007JulienNov 05.2011 — Take care and eliminate accents in names or identifiers...

A [I]document.Jatektermeretek.sz&#233;l.value;[/I] can not give the value of an input of name [I]sz&eacute;l[/I] (the [I]$eacute[/I] give the [I]&#233;[/I] in HTML but not in javascript). Change at first this name with a [I]szel[/I].

Then work with a debugger like Firebug with FireFox or other development error console...
Copy linkTweet thisAlerts:
@PSyhoauthorNov 05.2011 — Thank you for the help, I did just that, and the problem at hand has been dealt with by now.

Now I have a different problem.

The code:

[CODE]document.onkeyup = alert("megnyomtad");[/CODE]

Doesn't work for me. For one as soon as I open the page it shows the alert box, and it doesn't work again. As soon as alertbox is closed, no matter what I do , it doesn't show up again.

Could you help with this too?
Copy linkTweet thisAlerts:
@007JulienNov 05.2011 — Document.onkeyup wait a function and not an instruction ? Try :

[CODE]function lrt(){alert("megnyomtad");}
document.onkeyup = lrt;

// or with an anonymous fonction
document.onkeyup=function(){alert("megnyomtad");} [/CODE]
Copy linkTweet thisAlerts:
@PSyhoauthorNov 05.2011 — Thanks it works, but it reacts when i press ENTER as well (when I want to close alert window).

It isn't bad (filtering will take care of that), but just out of curiosity: why is it so?

Thnks again, you're a great help.

I almost forgot, how to deal with the fact that IE and FF works with it differently?
Copy linkTweet thisAlerts:
@007JulienNov 05.2011 — Try this
[CODE]
document.onkeyup = function(e){var k=e?e.which:window.event.keyCode,t=e?e.target:window.event.srcElement;
if (k==13) return;// for Enter
alert("The key is "+k);
// work with other keys and t the target
}
[/CODE]
Copy linkTweet thisAlerts:
@PSyhoauthorNov 05.2011 — Thanks, but what is that[CODE]t=e?e.target:window.event.srcElement;[/CODE] for?
Copy linkTweet thisAlerts:
@PSyhoauthorNov 05.2011 — Next question( hopefully the last)

I need the innerHTML src attributes of the pictures.

if the src value of image in cell id x is 1.png, then the src value of image in cell id x+1 needs to be 2.png.

And vice versa.
Copy linkTweet thisAlerts:
@007JulienNov 05.2011 — First question. The argument [I]e[/I] (the event object) of the function do not exist with Internet Explorer but is done by [I]window.event[/I].

To determine the key we test e, to keep e.which (if e exist) and window.event.keyCode (if e do not exist). It the same to determine the target (usually the input where the key board is used) t is given by e.target (if e exist) and window.event.srcElement (if not). You can remove this values, if you have not to work with this target.

I do not understand the second question the innerHTML of a cell will give all the tag img and the src attribute of the picture...
×

Success!

Help @PSyho spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.18,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...