473,385 Members | 1,593 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,385 software developers and data experts.

how to retrieve the data in array with html element access?

Hi Guys
I dont really know how to do this: if there are a page of others,
some data are embedded inside the data array like this:

<script language="JavaScript" type="text/javascript">
<!--
var jsData = new Array();
jsData[0] = {bowl:"I", year:1967, winner:"Packers", winScore:35,
loser:"Chiefs", losScore:10};
jsData[1] = {bowl:"II", year:1968, winner:"Packers", winScore:33,
loser:"Raiders (Oakland)", losScore:14};
jsData[2] = {bowl:"III", year:1969, winner:"Jets", winScore:16,
loser:"Colts (Balto)", losScore:7};
jsData[3] = {bowl:"IV", year:1970, winner:"Chiefs", winScore:23,
loser:"Vikings", losScore:7};
jsData[4] = {bowl:"V", year:1971, winner:"Colts (Balto)", winScore:16,
loser:"Cowboys", losScore:13};
--!>

Now only interested in these data,I want to export it to some format
that i like ,store somewhere else, How can I do this?

I know inside javascript ,you just use it's variable name to access
it ,but how about out side? just like we access html elements by it's
tag name, can we just use some" xpath or DOM way" to access this
array?

especially I'm using ruby(and Hpricot) to process some page content,
now the choice for me is just use some regular expression to deal it
like a dead string, not an array.....really appriciate if someone give
me a hint

thanks !
May 31 '08 #1
4 2174
SAM
Harry a écrit :
Hi Guys
I dont really know how to do this: if there are a page of others,
some data are embedded inside the data array like this:

<script language="JavaScript" type="text/javascript">
<!--
var jsData = new Array();
jsData[0] = {bowl:"I", year:1967, winner:"Packers", winScore:35,
loser:"Chiefs", losScore:10};
jsData[1] = {bowl:"II", year:1968, winner:"Packers", winScore:33,
loser:"Raiders (Oakland)", losScore:14};
jsData[2] = {bowl:"III", year:1969, winner:"Jets", winScore:16,
loser:"Colts (Balto)", losScore:7};
jsData[3] = {bowl:"IV", year:1970, winner:"Chiefs", winScore:23,
loser:"Vikings", losScore:7};
jsData[4] = {bowl:"V", year:1971, winner:"Colts (Balto)", winScore:16,
loser:"Cowboys", losScore:13};
--!>

Now only interested in these data,I want to export it to some format
that i like ,store somewhere else, How can I do this?
a kind of csv in an hidden field to submit somewhere ?

function xfer() {
var report = document.forms[0].hiddenValues;
for(var i in jsData) {
report.value += i+';';
for(var k in jsData[i]) report.value += jsData[i][k]+';';
report.value += '\n';
}
// to see what happens
document.getElementById('inf').innerHTML = report.value;
}
<p><button onclick="xfer();">txfer</button></p>
<form action="repport.php">
<input type=hidden name="hiddenValues">
<input type=submit>
</form>
<pre id="inf">
</pre>
I know inside javascript ,you just use it's variable name to access
it ,but how about out side? just like we access html elements by it's
tag name, can we just use some" xpath or DOM way" to access this
array?
var E = document.forms[0].hiddenValues.value.split('\n');
var txt = '<table border=1>', T='';
for(var i=0, L = E.length; i<L; i++) {
txt += '<tr>';
T = E[i].split(';');
for(var k=0, S = T.length; k<S; k++)
txt += '<td>'+T[k]+'<\/td>';
txt += '<\/tr>';
}
txt += '<\/table>';
document.getElementById('result').innerHTML = txt;
<div id="result"></div>
or ... :

<script type="text/javascript">
var txt = '<table border=1><tr>';
for(var k in jsData[0]) {
txt += '<th>'+k+'<\/th>';
}
txt += '<\/tr>';
for(var i in jsData) {
txt += '<tr><th>'+i+'<\/th>';
for(var k in jsData[i]) txt += '<td>'+jsData[i][k]+'<\/td>';
txt += '<\tr>';
}
txt += '<\/table>';
document.write(txt);
</script>

--
sm
May 31 '08 #2
Harry wrote:
<script language="JavaScript" type="text/javascript">
<!--
var jsData = new Array();
jsData[0] = {bowl:"I", year:1967, winner:"Packers", winScore:35,
loser:"Chiefs", losScore:10};
jsData[1] = {bowl:"II", year:1968, winner:"Packers", winScore:33,
loser:"Raiders (Oakland)", losScore:14};
jsData[2] = {bowl:"III", year:1969, winner:"Jets", winScore:16,
loser:"Colts (Balto)", losScore:7};
jsData[3] = {bowl:"IV", year:1970, winner:"Chiefs", winScore:23,
loser:"Vikings", losScore:7};
jsData[4] = {bowl:"V", year:1971, winner:"Colts (Balto)", winScore:16,
loser:"Cowboys", losScore:13};
var jsData = [
{bowl:"I", year:1967, winner:"Packers", winScore:35, ...},
...
};
--!>
http://validator.w3.org/#validate_by_input+with_options
Now only interested in these data,I want to export it to some format
that i like ,store somewhere else, How can I do this?

I know inside javascript ,you just use it's variable name to access
it ,but how about out side? just like we access html elements by it's
tag name, can we just use some" xpath or DOM way" to access this
array?
No.
especially I'm using ruby(and Hpricot) to process some page content,
now the choice for me is just use some regular expression to deal it
like a dead string, not an array.....really appriciate if someone give
me a hint
Suppose you have control over the content, it would be easier to parse if
you used initializers instead of constructors and several assigning
statements (see above). JSON does this: <http://json.org/>

But if you had control over the content, there would be no need for you to
parse anything as you have the data already available in its raw form (that
was the basis for the generated client-side code).

So ISTM you are asking the wrong question, and, given that you are using
Ruby (and Hpricot, whatever this is), you are probably also asking it in
the wrong place.
PointedEars
--
var bugRiddenCrashPronePieceOfJunk = (
navigator.userAgent.indexOf('MSIE 5') != -1
&& navigator.userAgent.indexOf('Mac') != -1
) // Plone, register_function.js:16
May 31 '08 #3
Thomas 'PointedEars' Lahn wrote:
Harry wrote:
><script language="JavaScript" type="text/javascript">
<!--
var jsData = new Array();
jsData[0] = {bowl:"I", year:1967, winner:"Packers", winScore:35,
loser:"Chiefs", losScore:10};
jsData[1] = {bowl:"II", year:1968, winner:"Packers", winScore:33,
loser:"Raiders (Oakland)", losScore:14};
jsData[2] = {bowl:"III", year:1969, winner:"Jets", winScore:16,
loser:"Colts (Balto)", losScore:7};
jsData[3] = {bowl:"IV", year:1970, winner:"Chiefs", winScore:23,
loser:"Vikings", losScore:7};
jsData[4] = {bowl:"V", year:1971, winner:"Colts (Balto)", winScore:16,
loser:"Cowboys", losScore:13};

var jsData = [
{bowl:"I", year:1967, winner:"Packers", winScore:35, ...},
...
};
Must be

];

of course.
PointedEars
--
var bugRiddenCrashPronePieceOfJunk = (
navigator.userAgent.indexOf('MSIE 5') != -1
&& navigator.userAgent.indexOf('Mac') != -1
) // Plone, register_function.js:16
Jun 1 '08 #4
On Jun 1, 4:19 pm, Thomas 'PointedEars' Lahn <PointedE...@web.de>
wrote:
Thomas 'PointedEars' Lahn wrote:
Harry wrote:
var jsData = [
{bowl:"I", year:1967, winner:"Packers", winScore:35, ...},
...
};

Must be

];

of course.
Ironically, that is both the fix to the syntax error and your personal
smiley :) .
Jun 2 '08 #5

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

Similar topics

0
by: Chung Leong | last post by:
My contribution to the comp.lang.php FAQ: ------------------------------------------------------------- Q: How do I retrieve a page from a web site? A: Pass a URL to file() or...
5
by: David Rasmussen | last post by:
Some sites seem to be session driven in the sense that if I visit the homepage and do a few clicks I can navigate anywhere I want, but if I paste the current location into a new browser window...
6
by: Chris Styles | last post by:
Dear All, I've been using some code to verify form data quite happily, but i've recently changed the way my form is structured, and I can't get it to work now. Originally : The form is...
22
by: VK | last post by:
A while ago I proposed to update info in the group FAQ section, but I dropped the discussion using the approach "No matter what color the cat is as long as it still hounts the mice". Over the last...
5
by: Richard Delorme | last post by:
The n869 draft says: J.2 Undefined behavior The behavior is undefined in the following circumstances: -- An array subscript is out of range, even if an object is ...
13
by: kev | last post by:
Hi all, I have created a database for equipments. I have a form to register the equipment meaning filling in all the particulars (ID, serial, type, location etc). I have two buttons at the end...
19
Atli
by: Atli | last post by:
Introduction At some point, all web developers will need to collect data from their users. In a dynamic web page, everything revolves around the users input, so knowing how to ask for and collect...
4
by: Harry | last post by:
Hi Guys I dont really know how to do this: if there are a page of others, some data are embedded inside the data array like this: <script language="JavaScript" type="text/javascript"> <!-- var...
7
by: lovecreatesbea... | last post by:
Is it always legal to cast expressions of type of multi-dimension array to type of pointer? Including: T to T* , T to T* , T to T* , and so on... For example: int *mtxrot1d(int *p,...
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...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

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.