By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
437,600 Members | 1,861 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 437,600 IT Pros & Developers. It's quick & easy.

Simple Javascript Conundrum

P: n/a
Hi

Heres how the following code works. A user selects a number from a
listbox, and then javascript generates that many textboxes.
ie. If a user selects 5 from the listbox, then 5 text boxes will
appear. Problem is, javascript blanks the page out first. We really
need the textboxes to appear underneath the listbox, instead of
clearing the screen first.

<head>
<script type="text/javascript">
function CheckDropDown(val)
{
var phil = parseInt(val);
document.write("<table border=\'0\' width=\'100%\' id=\'table1\'
cellspacing=\'0\' cellpadding=\'0\' bgcolor=\'#FFE1FF\'>");
for (i=1;i<=phil;i++)
{
this.document.write("<TR><TD width=\'200\'>Box No: " + i +
"</td><td><input type=\'text\' name=\'Box"+i+"\'
size=\'20\'></td></tr>");
}
document.write("</table>");
}
</script>
</head>
<body>
<form method="POST" action="--WEBBOT-SELF--" name="form1">
<!--webbot bot="SaveResults" U-File="D:\Projects\City Car
Club\_private\form_results.csv" S-Format="TEXT/CSV"
S-Label-Fields="TRUE" -->
<p>&nbsp;</p>
<p>Is your partner a member? <select size="1" name="Partner_List"
onchange="CheckDropDown(this.value);return false">
<option selected value="please select">please select</option>
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
<option value="4">4</option>
<option value="5">5</option>
<option value="50000">50000</option>
</select></p>
<p>&nbsp;</p>
</form>
</body>

Oct 13 '05 #1
Share this Question
Share on Google+
4 Replies


P: n/a
JRS: In article <11**********************@g47g2000cwa.googlegroups .com>
, dated Thu, 13 Oct 2005 11:44:16, seen in news:comp.lang.javascript,
go****@budget-edi.co.uk posted :

Heres how the following code works. A user selects a number from a
listbox, and then javascript generates that many textboxes.
ie. If a user selects 5 from the listbox, then 5 text boxes will
appear. Problem is, javascript blanks the page out first. We really
need the textboxes to appear underneath the listbox, instead of
clearing the screen first.
You should read the newsgroup FAQ before asking simple questions.

var phil = parseInt(val);
This seems to be a case where the second parameter is not needed; but
var phil = +val
should do instead.
document.write("<table border=\'0\' width=\'100%\' id=\'table1\'
cellspacing=\'0\' cellpadding=\'0\' bgcolor=\'#FFE1FF\'>");


Code posted to News should be executable by copy'n'paste. Therefore,
don't let your posting agent line-wrap; do it yourself. To ease this,
indent by the reasonable minimum when showing structure. You can change
TAB into SPACE SPACE for posting.

You don't need, ISTM, to escape those ' characters with \ .

....

See FAQ section 4.15.

<FAQENTRY> 4.15 start : add something like "After a page is loaded, the
first use of document.write[ln] will clear it before writing.".

--
John Stockton, Surrey, UK. ?@merlyn.demon.co.uk Turnpike v4.00 IE 4
<URL:http://www.jibbering.com/faq/> JL/RC: FAQ of news:comp.lang.javascript
<URL:http://www.merlyn.demon.co.uk/js-index.htm> jscr maths, dates, sources.
<URL:http://www.merlyn.demon.co.uk/> TP/BP/Delphi/jscr/&c, FAQ items, links.
Oct 14 '05 #2

P: n/a
Dr John Stockton said the following on 10/14/2005 9:07 AM:
JRS: In article <11**********************@g47g2000cwa.googlegroups .com>
, dated Thu, 13 Oct 2005 11:44:16, seen in news:comp.lang.javascript,
go****@budget-edi.co.uk posted :


<snip>
var phil = parseInt(val);

This seems to be a case where the second parameter is not needed; but
var phil = +val
should do instead.


Yet:

var phil = Number(val);

Is both "good enough" and self-documenting. It also does not use the
overloaded +

<snip>
See FAQ section 4.15.

<FAQENTRY> 4.15 start : add something like "After a page is loaded, the
first use of document.write[ln] will clear it before writing.".


document.write has nothing to do with dynamically changing the current
page. There should be something in the FAQ (or notes) about the improper
use of document.write but 4.15 isn't the right place.

--
Randy
comp.lang.javascript FAQ - http://jibbering.com/faq & newsgroup weekly
Oct 14 '05 #3

P: n/a
JRS: In article <hP********************@comcast.com>, dated Fri, 14 Oct
2005 18:41:09, seen in news:comp.lang.javascript, Randy Webb
<Hi************@aol.com> posted :
Dr John Stockton said the following on 10/14/2005 9:07 AM:
JRS: In article <11**********************@g47g2000cwa.googlegroups .com>
, dated Thu, 13 Oct 2005 11:44:16, seen in news:comp.lang.javascript,
go****@budget-edi.co.uk posted :
var phil = parseInt(val);

This seems to be a case where the second parameter is not needed; but
var phil = +val
should do instead.


Yet:

var phil = Number(val);

Is both "good enough" and self-documenting. It also does not use the
overloaded +


Unary + is not overloaded; and there is no harm in using an overloaded
operator. I expect your code uses binary +, in each sense, quite often.

<snip>
See FAQ section 4.15.

<FAQENTRY> 4.15 start : add something like "After a page is loaded, the
first use of document.write[ln] will clear it before writing.".


document.write has nothing to do with dynamically changing the current
page. There should be something in the FAQ (or notes) about the improper
use of document.write but 4.15 isn't the right place.


The first sentence is not true (so neither is the end of the second).
Often, people try to use document.write for that very purpose. When
they find that they have a problem, they may well search the FAQ for
"document.write". At present, they'll find nothing helpful that way.
Grow up.

--
John Stockton, Surrey, UK. ?@merlyn.demon.co.uk Turnpike v4.00 IE 4
<URL:http://www.jibbering.com/faq/> JL/RC: FAQ of news:comp.lang.javascript
<URL:http://www.merlyn.demon.co.uk/js-index.htm> jscr maths, dates, sources.
<URL:http://www.merlyn.demon.co.uk/> TP/BP/Delphi/jscr/&c, FAQ items, links.
Oct 15 '05 #4

P: n/a
Dr John Stockton said the following on 10/15/2005 11:40 AM:
JRS: In article <hP********************@comcast.com>, dated Fri, 14 Oct
2005 18:41:09, seen in news:comp.lang.javascript, Randy Webb
<Hi************@aol.com> posted :
Dr John Stockton said the following on 10/14/2005 9:07 AM:

JRS: In article <11**********************@g47g2000cwa.googlegroups .com>
, dated Thu, 13 Oct 2005 11:44:16, seen in news:comp.lang.javascript,
go****@budget-edi.co.uk posted :
var phil = parseInt(val);
This seems to be a case where the second parameter is not needed; but
var phil = +val
should do instead.
Yet:

var phil = Number(val);

Is both "good enough" and self-documenting. It also does not use the
overloaded +

Unary + is not overloaded; and there is no harm in using an overloaded
operator. I expect your code uses binary +, in each sense, quite often.


I said nothing about the "Unary +", I said the overloaded + operator.
And yes, it is overloaded.

Second, the code I posted is indeed what I said it to be. It is
self-documenting and (in your words) "good enough".

<snip>
See FAQ section 4.15.

<FAQENTRY> 4.15 start : add something like "After a page is loaded, the
first use of document.write[ln] will clear it before writing.".
document.write has nothing to do with dynamically changing the current
page. There should be something in the FAQ (or notes) about the improper
use of document.write but 4.15 isn't the right place.

The first sentence is not true (so neither is the end of the second).


It is 100% factually correct. You do not dynamically *change* a page
using document.write, you use document.write to dynamically *generate*
the page.
Often, people try to use document.write for that very purpose.
Then they need a good reference. Using the incorrect approach doesn't
make the approach part or even related to the solution other than maybe
a "what not to do" answer.
When they find that they have a problem, they may well search the FAQ for
"document.write". At present, they'll find nothing helpful that way.


And that is because document.write has nothing to do with dynamically
changing a page. Your reasoning that if a person is wanting to
"dynamically change a page" that they would search for "document.write"
is seriously flawed. They search for what they are trying to do, not
what they think the solution might be.

--
Randy
comp.lang.javascript FAQ - http://jibbering.com/faq & newsgroup weekly
Oct 15 '05 #5

This discussion thread is closed

Replies have been disabled for this discussion.