/    Sign up×
Community /Pin to ProfileBookmark

a little knowledge is dangerious

Can some one help me please,

I am trying to use a javascript to create a table for user input, the number of rows in the table is controlled by the user through the input text box.

My problem is that when the user enters the number of lines required only the url gets the addition of the number entered, this is the code I am using.
What have I done wrong?

<html>
<head>
<script type=”text/javascript”>

function itemtable()

{
var a = document.numlines.number.value;
document.write.(“<h1>Line Item Details</h1>”);
document.write(“The number is ” +a+);
document.write(“<table border=2 width=100%”);
document.write(“<tr>”);
document.write(“<th>Item No.</th><th>1</th><th>2</th><th>3</th>”);

for (var i = 1; i <= a; i++ ) {
document.write(“<tr>”);
document.write(“<td>”+i+”<td><input type=text name=item3″+i+”></td><td><input type=text name=item2″+i+”></td><td><input type=text name=item1″+i+”></td>”);
document.write(“</tr>”);
}

document.write(“</table>”);

}
</script>

</head>
<body>

<form name=”numlines”>
<table border=”2″>
<tr>
<td><input type=”text” value=”” onchange=”itemtable()” name=”number”>Number of lines required</td>
</tr>
</table>
</form>

</body>
</html>

Regards

to post a comment
JavaScript

3 Comments(s)

Copy linkTweet thisAlerts:
@A1ien51Feb 01.2010 — You cna not use document.write after the page loads. You need to use innerHTML or appendChild

Eric
Copy linkTweet thisAlerts:
@Vince616Feb 01.2010 — Hi bud

You main problem was that the form was trying to submit itself so to stop it from doing that you need to change the line

[CODE]<form name="numlines">[/CODE]

to

[CODE]<form name="numlines" onsubmit="return false">[/CODE]

You have two other errors in there as well

[CODE]document.write.("<h1>Line Item Details</h1>");
document.write("The number is " +a+);[/CODE]

they should be

[CODE]document.write("<h1>Line Item Details</h1>");
document.write("The number is " +a);[/CODE]

Your script will work after you make these changes

V
Copy linkTweet thisAlerts:
@tonkkaaauthorFeb 02.2010 — Great, thanks works now.

S
×

Success!

Help @tonkkaa 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 6.17,
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: @nearjob,
tipped: article
amount: 1000 SATS,

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

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