Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Extract Value From Multiple Tags

Status
Not open for further replies.

JBorges

Technical User
Jan 12, 2009
57
DK
Hi,

I'm designing a Bible for iPhone and use Javascript to extract a verse into a label when the verse is touched. That's why I'm asking for help in this forum.

A typical HTML file look like this:

Code:
<a href="" id="1:1">Now these are the names of Israel’s sons who came into Egypt with Jacob; each man and his household came:</a>
<a href="" id="1:2">Reu´ben, Sim´e·on, Le´vi and Judah,</a>
<a href="" id="1:3">Is´sa·char, Zeb´u·lun and Benjamin,</a> 
etc...

with this code I can extract a verse into a label
Code:
document.getElementsByTagName('a')[0].innerHTML;

When I implement the above JS code into my action in my iPhone app it only extracts the text of the first verse. My question is, how can I extract any given verse into a label? What does the JS code look like?

--Philip
 
document.getElementsByTagName('a')[[red]0[/red]].innerHTML;

Change the value between brackets to whatever number your verse is.

0 refers t0 the first link it finds, 1 would be the next one etc...



----------------------------------
Phil AKA Vacunita
----------------------------------
Ignorance is not necessarily Bliss, case in point:
Unknown has caused an Unknown Error on Unknown and must be shutdown to prevent damage to Unknown.

Behind the Web, Tips and Tricks for Web Development.
 
Yes that is true but that would require a set of 100s lines of document.getElementsByTagName('a')[0].innerHTML;
document.getElementsByTagName('a')[1].innerHTML;
document.getElementsByTagName('a')[2].innerHTML;
etc...

But I'm looking for a way for JS to extract the verse no matter what verse I press.

I'm thinking that [0].innerHTML should be a global variable like .innerHTML. But I'm not sure how that is accomplished.

Any ideas?
 
If you are using an onClick event of the link you can use the "this" reference to get the link that was clicked its innerHTML.

For instance:
Code:
<a href="" id="1:1" [red]onClick="get_line(this);"[/red]>Now these are the names of Israel's sons who came into Egypt with Jacob; each man and his household came:</a>
<a href="" id="1:2" [red]onClick="get_line(this);"[/red]>Reu´ben, Sim´e·on, Le´vi and Judah,</a>
<a href="" id="1:3" [red]onClick="get_line(this);"[/red]>Is´sa·char, Zeb´u·lun and Benjamin,</a>


Code:
get_line(lineObj){
var label= lineObj.innerHTML;
}

----------------------------------
Phil AKA Vacunita
----------------------------------
Ignorance is not necessarily Bliss, case in point:
Unknown has caused an Unknown Error on Unknown and must be shutdown to prevent damage to Unknown.

Behind the Web, Tips and Tricks for Web Development.
 
Thanks.

I'll see if I can embed it in my iPhone app.

--Philip
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top