Connecting Tech Pros Worldwide Forums | Help | Site Map

two questions

Darius Fatakia
Guest
 
Posts: n/a
#1: Jul 20 '05
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>



Dennis M. Marks
Guest
 
Posts: n/a
#2: Jul 20 '05

re: two questions


I have read the following message from "Darius Fatakia"
<darius_fatakia@yahoo.com>
and have decided to lend my vast knowledge.

The writer said:[color=blue]
> 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>
>
>
>
>[/color]

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! =-----
Randy Webb
Guest
 
Posts: n/a
#3: Jul 20 '05

re: two questions


Dennis M. Marks wrote:[color=blue]
> I have read the following message from "Darius Fatakia"
> <darius_fatakia@yahoo.com>
> and have decided to lend my vast knowledge.
>[/color]
[color=blue][color=green]
>>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)?[/color][/color]

<--snip-->
[color=blue]
> For the color look for info on CSS.[/color]

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/

Robert
Guest
 
Posts: n/a
#4: Jul 20 '05

re: two questions


In article <c0mglp$eee$1@news.Stanford.EDU>,
"Darius Fatakia" <darius_fatakia@yahoo.com> wrote:
[color=blue]
>
> 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;
> }
> }[/color]

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
Closed Thread