Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Javascript > Using JS to change color of the contents of a span tag

Reply
Thread Tools

Using JS to change color of the contents of a span tag

 
 
Rob
Guest
Posts: n/a
 
      11-13-2004

Hi all,
Javascript is not my strong point but I have a little problem with a
function.

I have ASP code that displays form variables for x number of users.
Depending on the radio button they click, I highlite some text in red
over another form variable to show that it's mandatory. I use a <span>
tag for the text and a Javascript function to change the text color of
that user's mandatory field.

My Javascript call passes (i) to show which user I'm talking about but
the problem is I don't know how to change that user's text color.
Here's my function
<script language="JavaScript">
<!--
function ChangeTextColor(num){
membertype_1.style.color='red';
memberno_1.style.color='black';
lastname_1.style.color='black';
}

//-->
</script>
As you see, I'm not using the parameter "num" so it only works for the
first user. I need to know how to make it dynamic...I've tried

membertype_[+num+].style.color='red';

but that doesn't work.
Anyone know the syntax?

Thanks
Rob


*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
 
Reply With Quote
 
 
 
 
McKirahan
Guest
Posts: n/a
 
      11-13-2004
"Rob" <(E-Mail Removed)> wrote in message
news:4196692f$0$14507$(E-Mail Removed).. .
>
> Hi all,
> Javascript is not my strong point but I have a little problem with a
> function.
>
> I have ASP code that displays form variables for x number of users.
> Depending on the radio button they click, I highlite some text in red
> over another form variable to show that it's mandatory. I use a <span>
> tag for the text and a Javascript function to change the text color of
> that user's mandatory field.
>
> My Javascript call passes (i) to show which user I'm talking about but
> the problem is I don't know how to change that user's text color.
> Here's my function
> <script language="JavaScript">
> <!--
> function ChangeTextColor(num){
> membertype_1.style.color='red';
> memberno_1.style.color='black';
> lastname_1.style.color='black';
> }
>
> //-->
> </script>
> As you see, I'm not using the parameter "num" so it only works for the
> first user. I need to know how to make it dynamic...I've tried
>
> membertype_[+num+].style.color='red';
>
> but that doesn't work.
> Anyone know the syntax?
>
> Thanks
> Rob


Try the following:

<script type="text/javascript">
function ChangeTextColor(num) {
document.getElementById("membertype_"+num).style.c olor='red';
document.getElementById("memberno_"+num)style.colo r='black';
document.getElementById("lastname_"+num).style.col or='black';
}
</script>


 
Reply With Quote
 
 
 
 
McKirahan
Guest
Posts: n/a
 
      11-13-2004
"McKirahan" <(E-Mail Removed)> wrote in message
news:bfuld.28810$V41.18417@attbi_s52...
> "Rob" <(E-Mail Removed)> wrote in message
> news:4196692f$0$14507$(E-Mail Removed).. .
> >
> > Hi all,
> > Javascript is not my strong point but I have a little problem with a
> > function.
> >
> > I have ASP code that displays form variables for x number of users.
> > Depending on the radio button they click, I highlite some text in red
> > over another form variable to show that it's mandatory. I use a <span>
> > tag for the text and a Javascript function to change the text color of
> > that user's mandatory field.
> >
> > My Javascript call passes (i) to show which user I'm talking about but
> > the problem is I don't know how to change that user's text color.
> > Here's my function
> > <script language="JavaScript">
> > <!--
> > function ChangeTextColor(num){
> > membertype_1.style.color='red';
> > memberno_1.style.color='black';
> > lastname_1.style.color='black';
> > }
> >
> > //-->
> > </script>
> > As you see, I'm not using the parameter "num" so it only works for the
> > first user. I need to know how to make it dynamic...I've tried
> >
> > membertype_[+num+].style.color='red';
> >
> > but that doesn't work.
> > Anyone know the syntax?
> >
> > Thanks
> > Rob

>
> Try the following:
>
> <script type="text/javascript">
> function ChangeTextColor(num) {
> document.getElementById("membertype_"+num).style.c olor='red';
> document.getElementById("memberno_"+num)style.colo r='black';
> document.getElementById("lastname_"+num).style.col or='black';
> }
> </script>
>


Oops, I forgot one of the dots; try this instead:

<script type="text/javascript">
function ChangeTextColor(num) {
document.getElementById("membertype_"+num).style.c olor='red';
document.getElementById("memberno_"+num).style.col or='black';
document.getElementById("lastname_"+num).style.col or='black';
}
</script>


 
Reply With Quote
 
Rob
Guest
Posts: n/a
 
      11-14-2004

Perfect. Thank you very much.

Rob


*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
I'm looking for html cleaner. Example : convert <h1><span><font>my title</font></span></h1> => <h1>my title</h1>… Stéphane Klein Python 2 03-30-2010 12:35 AM
Can span include span? Fulio Open HTML 5 06-26-2009 10:24 PM
CustomControls inherented from CompositeControl allways have as tag span - how to change this Rolf Welskes ASP .Net 2 10-05-2006 12:56 PM
Best way to dynamically change background color of a span or div? Boonish HTML 4 09-30-2006 09:01 AM
how do u invoke Tag b's Tag Handler from within Tag a's tag Handler? shruds Java 1 01-27-2006 03:00 AM



Advertisments