473,326 Members | 2,090 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,326 software developers and data experts.

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 1397
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
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
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
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
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
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
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
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
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
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
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

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.