473,394 Members | 2,160 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,394 software developers and data experts.

two questions

hi,

i am new to javascript and want to do two things. first, i'd like to change
the font color of text that is in a particular <td> tag. how do i do that (i
can change the background color, but i can't seem to figure out the font
color)?

also, i have an array of book titles and i would like the web user to be
able to be able to search through them. thanks so much. this is the code:

<?xml version="1.0" encoding="iso-8859-1"?>
<!DOCTYPE html PUBLIC
"-//w3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Find a Book</title>
<link rel="stylesheet" href="books.css" type="text/css" />
<script language="JavaScript" type="text/javascript">
<!--
function findBook() {
var i;
var found = 0;

var title = new Array("Death in Venice", "A portrait of the artist as a
young man", "A room with a view", "The house of spirits", "Of love and
shadows");
for(i = 0; i < title.length; i++) {
if(title[i] =~ /document.myform.title.value/) {
//title[i].test(document.myform.title.value)) {
document.myform.description.value = description[i];
found = 1;
break;
}
}

if(!found) {
document.myform.description.value = "Book not found";
}
return true;
}
-->
</script>
</head>
<body>
<br />
<h1>b o o k l a n d</h1>

<form name="myform" id="myform" action="">
<img src="spacer.gif" height="5" alt="s1" />
<table width="600" align="center" border="1"><tr><td>
<img src="spacer.gif" height="25" alt="s2" /><br />
<table width="350" align="center" border="0">
<tr>
<td valign="top" width="40%"><b>Author name:</b></td>
<td><input type="text" name="author" id="author" size="30" /></td>
</tr>
<tr>
<td valign="top"><b>Book title:</b></td>
<td><input type="text" name="title" id="title" size="30" /></td>
</tr>
<tr><td></td>
<td><input type="button" name="find" id="find" value="Find Book"
onclick="findBook();"/>
<input type="button" name="clear" id="clear" value="Clear Info"
onclick="document.myform.author.value=''; document.myform.title.value='';
document.myform.description.value=''"/>
</td>
</tr>
<tr><td><img src="spacer.gif" height="20" alt="s3" /></td></tr>
<tr>
<td valign="top"><b>Description:</b></td>
<td><textarea name="description" id="description" rows="15"
cols="40"></textarea><br /><img src="spacer.gif" height="25" alt="s4"
/></td>
</tr>
</table>
</td></tr></table>
</form>
</body>
</html>

Jul 20 '05 #1
3 2022
I have read the following message from "Darius Fatakia"
<da************@yahoo.com>
and have decided to lend my vast knowledge.

The writer said:
hi,

i am new to javascript and want to do two things. first, i'd like to change
the font color of text that is in a particular <td> tag. how do i do that (i
can change the background color, but i can't seem to figure out the font
color)?

also, i have an array of book titles and i would like the web user to be
able to be able to search through them. thanks so much. this is the code:

<?xml version="1.0" encoding="iso-8859-1"?>
<!DOCTYPE html PUBLIC
"-//w3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Find a Book</title>
<link rel="stylesheet" href="books.css" type="text/css" />
<script language="JavaScript" type="text/javascript">
<!--
function findBook() {
var i;
var found = 0;

var title = new Array("Death in Venice", "A portrait of the artist as a
young man", "A room with a view", "The house of spirits", "Of love and
shadows");
for(i = 0; i < title.length; i++) {
if(title[i] =~ /document.myform.title.value/) {
//title[i].test(document.myform.title.value)) {
document.myform.description.value = description[i];
found = 1;
break;
}
}

if(!found) {
document.myform.description.value = "Book not found";
}
return true;
}
-->
</script>
</head>
<body>
<br />
<h1>b o o k l a n d</h1>

<form name="myform" id="myform" action="">
<img src="spacer.gif" height="5" alt="s1" />
<table width="600" align="center" border="1"><tr><td>
<img src="spacer.gif" height="25" alt="s2" /><br />
<table width="350" align="center" border="0">
<tr>
<td valign="top" width="40%"><b>Author name:</b></td>
<td><input type="text" name="author" id="author" size="30" /></td>
</tr>
<tr>
<td valign="top"><b>Book title:</b></td>
<td><input type="text" name="title" id="title" size="30" /></td>
</tr>
<tr><td></td>
<td><input type="button" name="find" id="find" value="Find Book"
onclick="findBook();"/>
<input type="button" name="clear" id="clear" value="Clear Info"
onclick="document.myform.author.value=''; document.myform.title.value='';
document.myform.description.value=''"/>
</td>
</tr>
<tr><td><img src="spacer.gif" height="20" alt="s3" /></td></tr>
<tr>
<td valign="top"><b>Description:</b></td>
<td><textarea name="description" id="description" rows="15"
cols="40"></textarea><br /><img src="spacer.gif" height="25" alt="s4"
/></td>
</tr>
</table>
</td></tr></table>
</form>
</body>
</html>


and my reply is:
document.myform.description.value = description[i]; should be
document.myform.description.value = title[i];

For the color look for info on CSS.

I don't understand the slash before the > and if title[i] =~ unless
that is something in xml which is beyond my knowledge.

--
Dennis M. Marks
http://www.dcs-chico.com/~denmarks/
Replace domain.invalid with dcsi.net
-----= Posted via Newsfeeds.Com, Uncensored Usenet News =-----
http://www.newsfeeds.com - The #1 Newsgroup Service in the World!
-----== Over 100,000 Newsgroups - 19 Different Servers! =-----
Jul 20 '05 #2
Dennis M. Marks wrote:
I have read the following message from "Darius Fatakia"
<da************@yahoo.com>
and have decided to lend my vast knowledge.
hi,

i am new to javascript and want to do two things. first, i'd like to
change the font color of text that is in a particular <td> tag. how do
i do that (i can change the background color, but i can't seem to
figure out the font color)?


<--snip-->
For the color look for info on CSS.


To change the color, you script .color whereas you script
..backgroundColor to change the background color.

--
Randy
Chance Favors The Prepared Mind
comp.lang.javascript FAQ - http://jibbering.com/faq/

Jul 20 '05 #3
In article <c0**********@news.Stanford.EDU>,
"Darius Fatakia" <da************@yahoo.com> wrote:

var title = new Array("Death in Venice", "A portrait of the artist as a
young man", "A room with a view", "The house of spirits", "Of love and
shadows");
for(i = 0; i < title.length; i++) {
if(title[i] =~ /document.myform.title.value/) {
//title[i].test(document.myform.title.value)) {
document.myform.description.value = description[i];
found = 1;
break;
}
}


I know just above zero about XML. So, I could be totally
wrong here, but I hope not.

I'll expand a little on earlier comments.

// I don't think you want to split a string across an input line.
// I assume this was a posting thing.
var title = new Array(
"Death in Venice",
"A portrait of the artist as a young man",
"A room with a view",
"The house of spirits",
"Of love and shadows");

// I like putting {} on separate lines to verify that they
// are aligned correctly. Other people like other styles, I
// know, but I needed to sort out what was happening.
for(i = 0; i < title.length; i++)
{
// != means not equal
// == means equal
// = is always a assignment statement even in an if test
// Don't know what the leading slash is for
// nor the trailing (There are some langages were you have
// indicate that variables are a string in comparisions, but
// JavaScript isn't one of those.)

// In a production environment, you want to consider
// space normalization: eliminate leading, trailing, and
// multiple blanks.

if (title[i] == document.myform.title.value)
{
// I don't see the description arrary declared.
document.myform.description.value = description[i];
found = 1;
break;
}
}


I think you are confusing a tag end marking such as </tr> with a field
end marking >.

Questionable:
</tr>
<tr><td><img src="spacer.gif" height="20" alt="s3" />

Try:
</tr>
<tr><td><img src="spacer.gif" height="20" alt="s3">

For a simplistic way of "printing" out debug information that work in
HTML & Javascript, see my article:
http://groups.google.com/groups?hl=e...charles-FF349F.
22451509022004%40news02.west.earthlink.net

Re: Debug - Your own console
& be sure to use the second article.

Robert
Jul 20 '05 #4

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

Similar topics

0
by: softwareengineer2006 | last post by:
All Interview Questions And Answers 10000 Interview Questions And Answers(C,C++,JAVA,DOTNET,Oracle,SAP) I have listed over 10000 interview questions asked in interview/placement test papers for...
0
by: connectrajesh | last post by:
INTERVIEWINFO.NET http://www.interviewinfo.net FREE WEB SITE AND SERVICE FOR JOB SEEKERS /FRESH GRADUATES NO ADVERTISEMENT
2
by: freepdfforjobs | last post by:
Full eBook with 4000 C#, JAVA,.NET and SQL Server Interview questions http://www.questpond.com/SampleInterviewQuestionBook.zip Download the JAVA , .NET and SQL Server interview sheet and rate...
4
by: Drew | last post by:
I posted this to the asp.db group, but it doesn't look like there is much activity on there, also I noticed that there are a bunch of posts on here pertaining to database and asp. Sorry for...
8
by: Krypto | last post by:
Hi, I have used Python for a couple of projects last year and I found it extremely useful. I could write two middle size projects in 2-3 months (part time). Right now I am a bit rusty and trying...
0
by: ramu | last post by:
C# Interview Questions and Answers8 http://allinterviewsbooks.blogspot.com/2008/07/c-interview-questions-and-answers8.html C# Interview Questions and Answers7...
1
by: ramu | last post by:
C# Interview Questions and Answers8 http://allinterviewsbooks.blogspot.com/2008/07/c-interview-questions-and-answers8.html C# Interview Questions and Answers7...
0
by: ramu | last post by:
C# Interview Questions and Answers8 http://allinterviewsbooks.blogspot.com/2008/07/c-interview-questions-and-answers8.html C# Interview Questions and Answers7...
0
by: reema | last post by:
EJB Interview Questions http://interviewdoor.com/technical/EJB-Interview-Questions.htm CSS Interview Questions http://interviewdoor.com/technical/CSS-Interview-Questions.htm C Interview Questions...
0
by: reema | last post by:
EJB Interview Questions http://interviewdoor.com/technical/EJB-Interview-Questions.htm CSS Interview Questions http://interviewdoor.com/technical/CSS-Interview-Questions.htm C Interview Questions...
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: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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: 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...
0
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...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
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...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

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.