473,498 Members | 1,714 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Simple Javascript Conundrum

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
4 1407
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
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
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
331
by: google | last post by:
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...
4
1933
by: Jim Ford | last post by:
I have a single C file with the following code: int f2() { /* Blah-blah */ } int f1() { /* Blah-blah */
2
1203
by: Caladin | last post by:
I'm sure once someone answers this I'll feel really dumb. I'm a c++ programmer playing with c# an here's my conundrum I declare a class in the for public class Form1 :...
4
1705
by: Jim Owen | last post by:
I am storing all my application data in the application cache. Anytime I have a method as part of an asp.net form, I need to access the objects in the cache. The only way I can think of to do this...
26
11034
by: wardy | last post by:
Hi all, looking for a little bit of help.....I'm currently in the process of trying to understand the impact of the 508 guidelines on a web site that I am involved with, and I have a question...
2
3158
by: subnunciation | last post by:
i know, this shouldnt be a conundrum right? one just shouldnt divide by zero. but this is suddenly happening *all over* my site. after chasing the error here and there, i simplified things down to:...
10
6042
by: ljlolel | last post by:
So.. I have a form that submits to an ASP.net site made in C-sharp. The ASP site is not mine, i do not have the server side code. When I submit from my form by pressing the Submit button, I get...
24
6283
by: firstcustomer | last post by:
Hi, Firstly, I know NOTHING about Javascript I'm afraid, so I'm hoping that someone will be able to point me to a ready-made solution to my problem! A friend of mine (honest!) is wanting to...
2
1281
by: rjmlangley | last post by:
Hi Folks, I seem to have quite a conundrum here and I'm at my wits end. Essentially I have a HTML table where I'm trying to place a message at the top of the table should a value appear later in...
0
7125
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
1
6887
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
7379
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
5462
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
4910
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
4590
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3093
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3085
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
291
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.