Naresh C

Navigation

Skip navigation.

Search

Site navigation

Email conversation

Fromabc cba (Naresh C)
ToMe
SubjectNeed help on creating data entry table ( Array table....)
Date16 June 2004 16:39
Sir,

I'm not expert in javascript. 

Could you pleae help me in creating dynamic table
using javascript as a data-entry table, where, each
cell should be editable. After proving data to the
cells, I would like to use them for further
processing. (similar to creat an array 4x4, and use it
.....) 


Thanks,
NC
FromMe
ToNaresh C
SubjectRe: Need help on creating data entry table ( Array table....)
Date17 June 2004 9:26
Attachmenta script that produces an editable table
Please use a real name when sending me emails. Using a false name like 'abc
cba' makes it very difficult to see your email amongst hundreds of spam
emails.

Instead of just using a table, use a table with <input> elements in
the cells. You can use CSS to hide them so they do not look like inputs.

I have attached a script that should do what you need, if I have understood
you correctly.

hope this helps


Mark 'Tarquin' Wilton-Jones - author of http://www.howtocreate.co.uk/
FromNaresh C
ToMe
SubjectRe: Need help on creating data entry table ( Array table....)
Date17 June 2004 17:21
Mark:

Thanks for your reply.  
I was looking for the similar script you sent to me. 
With this, I will extend my application.  

Thanks a lot!
Naresh
FromNaresh C
ToMe
SubjectRe: Data Entry Table with OnBlur method on the input text (From Nick, NC)
Date7 July 2004 22:56
Attachmentscript that fails for several reasons
Mark:

I'm having some tough time to make this work( file
attached).

I created a data entry table, 4 rows and 3 column,
where data entry for all rows of the 2nd and 3rd
column. At table footer, I would like to disply the
sum of 2nd and 3rd column.   I'm using onblur method
on the input text, for some reson, IE is not accepting
it.

Pleae help me, as I'm a javascript novice, just a
beginner....


NICK
[Ed. different name, same email address ... hmmm ... ]
FromMe
ToNaresh C
SubjectRe: Data Entry Table with OnBlur method on the input text (From Nick, NC)
Date8 July 2004 15:52
Attachmentworking version of the script
Nick,

for a beginner, you seem to be doing some fairly advanced DOM scripting ....

ok, here's the bugs:

1. insertRow and insertCell should always use an index (I do not personally
recommend using these methods since they do not work in Internet Explorer
Mac, but since it also screws up creating inputs, this is not really an
issue for your script)
theBody.insertRow(0)

2. you should not use:
element.bgColor = 'blah';
instead, you should use:
element.style.backgroundColor = 'blah';

3. This is valid:
<TABLE ID="oTable">
BUT this is not:
var oTHead = oTable.createTHead();
although IE/win and Opera will allow you to do this, it is non standard.
The ID does not automatically create a variable in Mozilla/Netscape6+,
Safari/Konqueror, ICE, and IE/Mac. The correct (standards compliant) way
to do this is:
var oTHead = document.getElementById('oTable').createTHead();
IE and Opera also support this correct way.

4. quite a common mistake for all programmers:
if(j=1)
that is assigning the value 1 to j, it is not doing a comparrison. It
should be:
if(j==1)
two '=' signs, not one.

5. when using a function as an event handler, you cannot pass it parameters:
col_elemTxtName[i].onblur=total_area(sum_Row); //WRONG
col_elemTxtName[i].onblur=total_area; //correct
... but, you can do this ...
col_elemTxtName[i].onblur=function () { total_area(sum_Row); }

6. This is invalid:
vvv_total_area += 'row['+j+']col['+1+']'.value;
all you have done there is defined a string and asked for its value (which
is undefined). You need to look through the elements of the form to do this:
vvv_total_area += document.nameOfForm['row['+j+']col[1]'].value;
However, with elements created using DOM, they are not entered correctly
into the form's elements array, so instead, use an ID:
col_elemTxtName[i].id = "row["+i+"]col["+j+"]";
Of course, you also need the name atttribute so that if the form is
submitted, the data can be sent to the server, so just use the same name
and ID, and then use:
vvv_total_area += document.getElementById('row['+j+']col['+1+']').value;

7. This does not do what you think:
var col_elemTxtName = new Array(numCols);
arrays in JavaScript do not have a fixed length, so there is no need to
define the length. some browsers will interpret this as: "put this value in
the first array cell"

8. You have mixed up your quotes in these lines:
col_elemTxtName[i].name="row['+i+']col['+j+']";
you should use either " or ' but not both

9. innerText is only supported by IE and Opera. Use innerHTML instead.

10. strictly speaking, you should use 'setAttribute' here, although it does
actually work either way:
col_elemTxtName[i].size="4";

11. You need to use parseFloat to turn the strings in the text boxes into
numbers before adding them.


I have attached the script which works.


Mark 'Tarquin' Wilton-Jones - author of http://www.howtocreate.co.uk/
FromNaresh C
ToMe
SubjectRe: Data Entry Table with OnBlur method on the input text (From Nick, NC)
Date9 July 2004 13:01
Mark:

Thanks for your help. Not only you corrected the
program, but, you explained the syntax in details.
This is way beyond my expectations. Thanks once again
for help.....

Nick, NC
FromNaresh C
ToMe
SubjectRe: Data Entry Table with OnBlur method on the input text (From Nick, NC)
Date25 August 2004 15:33
Attachmentalmost working version of the script
Mark:

Please note that, with your help, I created a
javascript  interface. Using this, input data will be
transferred to the servlet.  So as to make it work, 
I'm having few difficulties as follows:

1.	Error message for  

	col_elemTxtName[i].class='likeText';  


2.	While selecting item from drop-down  for 'Basic
structural system' ex.'LG-Wall System', I do get any
error message. Please check function
update_basic_stru_system(), I may not be using proper
syntax...


3.	Over the server, using servlet,  I would like to
pass the values for output_level_ht[j][1] as defined
in function total_height().   As the values are stored
in an array, how do I read it servlet?  ( I mean, do I
have to first assign it to a sting? Not sure...as array
size is not fixed...) 


File attached

Thanks,
Nick
FromMe
ToNaresh C
SubjectRe: Data Entry Table with OnBlur method on the input text (From Nick, NC)
Date27 August 2004 10:32
> 1.    Error message for col_elemTxtName[i].class='likeText';

you must not set class, you must set className (basically the same thing,
but elements can have multiple classes and className was the way they chose
to deal with it)

col_elemTxtName[i].className = 'likeText';

> Please check function update_basic_stru_system()

you have put one function inside another by accident

function one()
{
...
function two()
{
...
}
}

the last } is in the wrong place

> I would like to pass the values for output_level_ht[j][1]


To pass array information, you can either use a 'for' loop to cycle through
the array and build a series of get data variables, or you can just put the
data into one long string and get the servlet to extract the right
information (using something like 'split'):
var theData = escape(output_level_ht[j].join('some unique string'));
location.href = 'newUrl.jsp?arrayData=' + theData;
FromNaresh C
ToMe
SubjectRe: Data Entry Table with OnBlur method on the input text (From Nick, NC)
Date02 October 2004 04:16
Attachmentsample script
Mark:

Could you please help me? 
Before I submit HTML form to the servlet, how do I
assign an array holding string values to form's input
value

[a _load_ of code]

I attached HTML file


Thanks
Nick
FromMe
ToNaresh C
SubjectRe: Data Entry Table with OnBlur method on the input text (From Nick, NC)
Date02 October 2004 16:51
you have already used the thing that you need; the join method.

document.forms[formName].inputName.value = arrayName.join('aUniqueString');

Then in your JSP servlet, you will need to use the split method to split
the string back into an array. I have never used JSP like this, so I am not
sure of the exact syntax.
something like:
String[] arrayName = request.getParameterValues("post_output_level_area").split("aUniqueString");
This site was created by Mark "Tarquin" Wilton-Jones.
Don't click this link unless you want to be banned from our site.