473,703 Members | 3,129 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

where to find rules about punctuation in JavaScript dynamic table population

Hello:

I previously posted a question about how to do populate an html table
dynamically with results from JavaScript Math and basic math. Dr Clue
responded and this started the learning curve. I think the terminology
for what I want to do is pass variables to the <td> 'workspace' (half
this statement might make sense).

The problem I am having is being overwhelmed with understanding the
context of each new statement, syntax etc.

I have had difficulty finding explanations of the use of proper
punctuation. I see for example, code with <td> and <tr> that also have
+ + surrounding what look like the desired variables.

Yet, obviously I am not understanding the proper usage because one of
two things happen; either a cut and pasted example was much more
complex than what I need and I can't get it running at all due to
missing parts, or I am buried with 'errors on page'.

Will html validation explain to me what heinous errors have been
committed?

I've looked at W3 std on the Web and books, and example after example,
but found little if any explanation of what the function is of each
punctuation element in these 'exotic' examples. I call them exotic
because I'm sure not finding them.

If posting a snip of code would be a better way to ask 'what's wrong',
I can do that.

One thing I think would work for me is simply a way to output
(document.write or whatever method) to a <td> "+ varname +" </td> kind
of thing. If I actually wrote something correctly, I didn't do it
consciously.

I've tried searching before posting, but obviously I'm looking for the
wrong thing or progress in my case is exceedingly slow.

Thank you
Murray

Sep 27 '05 #1
7 2571
jscheuer1
2 New Member
Sounds like you may be getting hung up on the proper use of quotes and plus signs. Basically, whatever type of quote you use to delimit a string, must be escaped inside of it and a string segment must be closed using its delimiting quote style before adding (the plus sign) a defined variable. You can use either single (') or double (") quotes to delimit a string. If quotes not used as delimiters are included in the string, it is best to use the type of quotes appearing the least frequently in the string to delimit it. An example:

[PHP]var animal='dog'

document.write( "Haven't you got a "+animal+" yet?")[/PHP]I used PHP code tags because they highlight the syntax of the statements well but, this is javascript. It will write this line to the page:

Haven't you got a dog yet?

In the code example the double quotes are the delimiters. If I had used single quotes to delimit the string, then I would had to escape the one used in the contraction:
Expand|Select|Wrap|Line Numbers
  1. document.write('Haven[COLOR=Red]\'[/COLOR]t you got a '+animal+' yet?')
Here, only the escaped single quote is syntax highlighted.
Sep 27 '05 #2
mu************* ******@yahoo.co m wrote:
Hello:

I previously posted a question about how to do populate an html table
dynamically with results from JavaScript Math and basic math. Dr Clue
responded and this started the learning curve. I think the terminology
for what I want to do is pass variables to the <td> 'workspace' (half
this statement might make sense).

The problem I am having is being overwhelmed with understanding the
context of each new statement, syntax etc.

[snip]
Look up "concatenat ion javascript".

"String surrounded by quotes" + variable +"Another string"

The "+" operator is overloaded in js, thus the context of the statement
dictates its function:

String + Number = String
"2"+2=="22"

Number + Number = Number
2+2==4

For example:
"2"+(2+2)== "24"
Number("2")+(2+ 2)==6 // convert String to Number
(2+2)+ +("2")==6 // using the "+" for the conversion +("2")

HTH
Mick

Sep 27 '05 #3
I am still having trouble evolving to the next level of enlightenment.

I've resigned myself to doing my calculations by multiplying array
elements and opening a new window and doc.write to the screen for a
printout option separate from the original web page.

With that working pretty well, I tried to pass contents of variables to
a table as <td> </td>content based on example code, but each sample or
advise I've received has 'new' elements or implied function I am not
grasping, and despite me efforts to go read and understand the context
of the other methods, it's just not sinking in.

I thought it might be simpler to post what I am TRYING to do, and then
perhaps what is missing will be obvious.

Below is a simplified example. The actual stuff is messier, and reads
from an input form but this boils down the math & malfunctioning table
parts. I realize I can clean it up by using "with Math..." and maybe
some other simplification.

The problem seems to be that I am not properly "enabling" the variables
for the table data. That's the hard part (for me) of dissecting someone
else's code; if I don't know the rules for each 'functional part',
mimicking something gives unpredictable results.

I think the open-ended flexibility of DOM is where I am lost. I can't
tell what is infinitely possible and what has rigid rules.

Also, can one increment a counting element by 0.5 in a JS 'for'
statement? I tried in VB and it seemed to work there.

Thanks

Murray
---------------------
<html>
<body>

<script type="text/javascript">
var AAA = new Array(4)

AAA[0] = 0.1*Math.round( 10*Math.log(32)/Math.log(2))
AAA[1] = 0.1*Math.round( 10*Math.log(16)/Math.log(2))
AAA[2] = 0.1*Math.round( 10*Math.log(8)/Math.log(2))
AAA[3] = 0.1*Math.round( 10*Math.log(5.6 56)/Math.log(2))

for (i=0;i<AAA.leng th;i++)
{
document.write( AAA[i] + "<br />")
}
</script>
<hr>
<table border="2">

<tr>
<td>AAA[0]</td>
<td>AAA[1]</td>
</tr>
<tr>
<td>AAA[2</td>
<td>AAA[3]</td>
</tr>
</table>

</body>
</html>

Oct 14 '05 #4
mu************* ******@yahoo.co m wrote:
I am still having trouble evolving to the next level of enlightenment.

I've resigned myself to doing my calculations by multiplying array
elements and opening a new window and doc.write to the screen for a
printout option separate from the original web page.

With that working pretty well, I tried to pass contents of variables to
a table as <td> </td>content based on example code, but each sample or
advise I've received has 'new' elements or implied function I am not
grasping, and despite me efforts to go read and understand the context
of the other methods, it's just not sinking in.

I thought it might be simpler to post what I am TRYING to do, and then
perhaps what is missing will be obvious.

Below is a simplified example. The actual stuff is messier, and reads
from an input form but this boils down the math & malfunctioning table
parts. I realize I can clean it up by using "with Math..." and maybe
some other simplification.

The problem seems to be that I am not properly "enabling" the variables
for the table data. That's the hard part (for me) of dissecting someone
else's code; if I don't know the rules for each 'functional part',
mimicking something gives unpredictable results.

I think the open-ended flexibility of DOM is where I am lost. I can't
tell what is infinitely possible and what has rigid rules.

Also, can one increment a counting element by 0.5 in a JS 'for'
statement? I tried in VB and it seemed to work there.

Thanks

Murray
---------------------
<html>
<body>

<script type="text/javascript">
var AAA = new Array(4)

AAA[0] = 0.1*Math.round( 10*Math.log(32)/Math.log(2))
AAA[1] = 0.1*Math.round( 10*Math.log(16)/Math.log(2))
AAA[2] = 0.1*Math.round( 10*Math.log(8)/Math.log(2))
AAA[3] = 0.1*Math.round( 10*Math.log(5.6 56)/Math.log(2))

theTable='<tabl e border="2"><tr> <td>';
theTable+=AAA[0];
theTable+='</td><td>';
theTable+=AAA[1];
theTable+='</td></tr><tr><td>';
theTable+=AAA[2];
theTable+='</td><td>';
theTable+=AAA[3];
theTable+=</td></tr></table>;
document.write( theTable);
//or
document.write( AAA.join("<BR>" ))

</script>

Mick

Oct 14 '05 #5
Thank you, Mick.

One more question regarding the table format below. It is apparent that
yours has a totally different 'style' with more 'rules' than the most
primitive form I employed.

Is there a description of what structure your code conforms to?
Is it DOM? The ; at end of each line and the variation in = and += are
the kind of subtleties that have to be right and one will never get
right without grasping how it all goes together.

I bounce from one on-line tutorial to another and find that I'm
learning one command at a time but not the BIG picture.

It's analogous to being illiterate and wishing to read Shakespeare.
Figuring out how to build a learning curve is the next challenge.

I suppose if I needed it for work I could take training courses. For a
not-for-profit path, could you recommend any reading? It would be nice
if I could answer more of my own questions, so I would be the only one
hearing them repeated.

Thanks

Murray
theTable='<tabl e border="2"><tr> <td>';
theTable+=AAA[0];
theTable+='</td><td>';
theTable+=AAA[1];
theTable+='</td></tr><tr><td>';
theTable+=AAA[2];
theTable+='</td><td>';
theTable+=AAA[3];
theTable+=</td></tr></table>;
document.write( theTable);
//or
document.write( AAA.join("<BR>" ))

</script>

Mick


Oct 15 '05 #6
mu************* ******@yahoo.co m wrote:
Thank you, Mick.

One more question regarding the table format below. It is apparent that
yours has a totally different 'style' with more 'rules' than the most
primitive form I employed.

Is there a description of what structure your code conforms to?
Is it DOM? The ; at end of each line and the variation in = and += are
the kind of subtleties that have to be right and one will never get
right without grasping how it all goes together.
a+=b
a=a+b
The expressions are equivalent, and are core javascript (part of the
language itself). The DOM is part of the browser, the DOM exposes
objects to javascript. (document, window etc.)
What I offered is a quick (and dirty) way of using js to write HTML. If
you are interested in the BIG picture, you need to familiarise yourself
with programming concepts - functions, parameters, scope, iteration etc.

The case that you present -stuffing array values into table cells- is
trivial, thus I offered a one-off solution.

I would approach the coding quite differently. I would look for a
*generic* way to accomplish the task at hand:

function stuffArrayValue sIntoTable(arra y,tableID){
//do stuff here
}

I try to avoid "document.write ()" if I can, in favour of DOM techniques.

function stuffArrayValue sIntoTable(arra y,tableID){
if(!tableID){
// create a table
}
else{
var theTable;
if(theTable=doc ument.getElemen tById(tableID)) {//Table exists
if(array.length >0){//"array" looks like an Array
//do stuff with the table and array
}
}
else{//Flaky ID, or non-DOM browser
return;//exit function
}
}

For further reading:
http://www.mozilla.org/docs/dom/refe...avascript.html

Mick

I bounce from one on-line tutorial to another and find that I'm
learning one command at a time but not the BIG picture.

It's analogous to being illiterate and wishing to read Shakespeare.
Figuring out how to build a learning curve is the next challenge.

I suppose if I needed it for work I could take training courses. For a
not-for-profit path, could you recommend any reading? It would be nice
if I could answer more of my own questions, so I would be the only one
hearing them repeated.

Thanks

Murray

theTable='<ta ble border="2"><tr> <td>';
theTable+=A AA[0];
theTable+=' </td><td>';
theTable+=A AA[1];
theTable+=' </td></tr><tr><td>';
theTable+=A AA[2];
theTable+=' </td><td>';
theTable+=A AA[3];
theTable+=</td></tr></table>;
document.writ e(theTable);
//or
document.writ e(AAA.join("<BR >"))

</script>

Mick


Oct 15 '05 #7
Thank you

Oct 16 '05 #8

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
3594
by: Raghuram Banda | last post by:
Hi all, I've created a table with Table Header and the table may or may not contain any rows initially. I've included a .css file in <head> section of my HTML script and I'm creating rows to the table dynamically using JavaScript (using DOM), and the problem is those created bby DOM are not following style sheet rules applicable for table rows and cells. But the rows created from within
16
2698
by: Safalra | last post by:
Frequently in ciwah people say 'but what about the users without JavaScript?', so I decided to do an experiment. It suggests 35% internet users do not have JavaScript turned on in their browsers. I'd appreciate it if people here had a look at my page on the experiment, and tell me if they see any methodological flaws, before I go and publicise it more widely: http://www.safalra.com/hypertext/html/nojavascript.html --- Safalra (Stephen...
3
3830
by: Al Wilkerson | last post by:
Hey, I have a Web Form with a drop down list, textbox, and search button. When click the search button an SQL server database is queried fordata. Once I have the data in a dataset I use the dataset to dynamically create a Html Table control. I want to display the table on another frame page (target="main") without the web form controls (i.e. the textbox, search button, and dropdown list). I just want the table displayed only on the...
0
1175
by: russ | last post by:
Hi all, I've got an web form with two things on it: * <table runat=server> * <asp:DropDownList> inside one of the <td> of the table. I only populate the dropdown inside a "if (!IsPostBack)". Everytime I postback I'm inserting a column into the table, the dropdown always remains in the last column. First time I postback the dropdown is populated okay. The second time its empty.
1
4834
by: russ | last post by:
Hi all, Here's a problem I'm having with a dynamic table. Following the guidelines here (http://www.codeproject.com/aspnet/dynamiccontrols.asp), which make perfect sense. The problem is that the table contains a SELECT box populated on the initial load. Every time I postback I'm inserting a column into the table, the dropdown always remains in the last column. First time I postback the dropdown is populated okay. The second time...
27
4615
by: one man army | last post by:
Hi All- I am new to PHP. I found FAQTS and the php manual. I am trying this sequence, but getting 'no zip string found:'... PHP Version 4.4.0 $doc = new DomDocument; $res = $doc->loadHTMLFile("./aBasicSearchResult.html"); if ( $res == true ) { $zip = $doc->getElementById('zipRaw_id')->value; if ( 0 != $zip ) {
22
2348
by: Christopher Nelson | last post by:
I have a little menu system which essentially takes HTML like: <div id='foo'></div> and retrieves foo.shtml from the server and inserts it inside the <div>. But sometimes I'd like foo.shtml to look like: <script language='JavaScript'> ...do something AJAX-y </script>
1
4168
by: Shoma | last post by:
Hi, I have a function(stored procedure) in the database. I need to pass the table name which is a variable. How do i do that? Example : I have 1st table : table name - cities location | city (text) | (text) --------------------- 1 bangalore 2 mangalore
3
4852
by: tokcy | last post by:
hi everyone, i am creating dynamic row in a table using javascript its working fine and now i want to create more than 1 table using javascript which is dynamic its also working fine but when i am taking the value of each table individually thats i am not able to get any value. if i get the value of table then its not taking properly. let me explain the whole scenario... i want to add product specification . it may vary in number of...
0
8749
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8662
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9109
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
8956
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7853
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6585
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4420
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 last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
3113
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
2057
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 can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.