/    Sign up×
Community /Pin to ProfileBookmark

[RESOLVED] Why this one not working?

1st code works fine:

[code]
<html>
<head>
<title>Sample code – Traversing an HTML Table with JavaScript and DOM Interfaces</title>
<script>
function start() {
// get the reference for the body
var body = document.getElementsByTagName(“body”)[0];

// creates a <table> element and a <tbody> element
var tbl = document.createElement(“table”);
var tblBody = document.createElement(“tbody”);

// creating all cells
for (var j = 0; j < 2; j++) {
// creates a table row
var row = document.createElement(“tr”);

for (var i = 0; i < 2; i++) {
// Create a <td> element and a text node, make the text
// node the contents of the <td>, and put the <td> at
// the end of the table row
var cell = document.createElement(“td”);
var cellText = document.createTextNode(“cell is row “+j+”, column “+i);
cell.appendChild(cellText);
row.appendChild(cell);
}

// add the row to the end of the table body
tblBody.appendChild(row);
}

// put the <tbody> in the <table>
tbl.appendChild(tblBody);
// appends <table> into <body>
body.appendChild(tbl);
// sets the border attribute of tbl to 2;
tbl.setAttribute(“border”, “2”);
}
</script>
</head>
<body onload=”start()”>
</body>
</html>
[/code]


*******************

why this 2nd code is not working?

[code]
<html>
<head>
<title>Sample code – Traversing an HTML Table with JavaScript and DOM Interfaces</title>
<script type=”text/javascript”>
function start() {
// get the reference for the body
var body = document.getElementsByTagName(“body”)[0];

// creates a <table> element and a <tbody> element
var tbl = document.createElement(“table”);
var tblBody = document.createElement(“tbody”);

// creating all cells
for (var j = 0; j < 2; j++) {
// creates a table row
var row = document.createElement(“tr”);

for (var i = 0; i < 2; i++) {
// Create a <td> element and a text node, make the text
// node the contents of the <td>, and put the <td> at
// the end of the table row
var cell = document.createElement(“td”);
var cellText = document.createTextNode(“cell is row “+j+”, column “+i);
cell.appendChild(cellText);
row.appendChild(cell);
}

// add the row to the end of the table body
tblBody.appendChild(row);
}

// put the <tbody> in the <table>
tbl.appendChild(tblBody);
// appends <table> into <body>
body.appendChild(tbl);
// sets the border attribute of tbl to 2;
tbl.setAttribute(“border”, “2”);
}
</script>

<script type=”text/javascript”>
function submitform()
{ alert(“Thank You For Submitting The Form”) }
</script>

</head>
<body onload=””>
<input type=”button” onclick=”start()” value=”Add Product Order” />
</body>
</html>
[/code]

to post a comment
JavaScript

5 Comments(s)

Copy linkTweet thisAlerts:
@FangJun 07.2008 — Change the function name; in IE [I]start[/I] is a reserved word.
Copy linkTweet thisAlerts:
@beginner_prithvauthorJun 09.2008 — cooooolll!!!! its working bro.. but just tell me why did it worked for the first code?
Copy linkTweet thisAlerts:
@KorJun 09.2008 — In fact I don't think it is a javascript reserved word. It is rather an ActionScript command, and I suspect IE (and only IE) makes the confusion. I confess I don't know why this happens when the event calls this named function within [I]some elements only[/I] (INPUT, for instance) but not when the event is attached to others (WINDOW, SPAN...)

Anyway. The [B]complete[/B] list of the [I]reserved and used[/I] words was not published yet :rolleyes: Probably you should guide yourself upon an empiric hypothesis: If it "sounds" like an obvious method, action or global object of a client-side language or a related language, don't use that word ? The probability for [B]start()[/B], [B]stop()[/B] or [B]go()[/B], for instance, to be part of any languages is so high, that it is wise to avoid such of. ?
Copy linkTweet thisAlerts:
@beginner_prithvauthorJun 10.2008 — lol... kor thnx bro for ur help.. Fang thnx to u also ?
Copy linkTweet thisAlerts:
@KorJun 10.2008 — I've found the answer from a friend expert. He said so:

"In IE, input elements have a property named [B]start[/B]. When you write script inline in an event handler, the scope of that event handler will contain all the properties of the form control itself, outside that scope will be the form itself, I'm not sure but I believe the document may come next in the scope hierarchy, and the window object comes at the bottom of the scope chain. As such, a property name on the input element will shadow a function name on the window object."
×

Success!

Help @beginner_prithv 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.3,
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: @Yussuf4331,
tipped: article
amount: 1000 SATS,

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

tipper: @Samric24,
tipped: article
amount: 1000 SATS,
)...