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

using a string with object name to refrence object

I am new to JavaScript and I am currently having a problem that I can find
no clear solution to. I have a series of button contained in a row. These
rows are defined as follows:
<tr> <!--This is Mondays row -->
<td><button type="button" value="Monday" id="Monday" style="BACKGROUND:
yellow" onclick='ScheduleDay("Monday")'>Monday</button></td>
<td><button type="button" value="M830" id="M830" style="BACKGROUND:
white">8:30</button></td>
<td><button type="button" value="M900" id="M900" style="BACKGROUND:
white">9:00</button></td>
<td><button type="button" value="M930" id="M930" style="BACKGROUND:
white">9:30</button></td>
<td><button type="button" value="M1000" id="M1000" style="BACKGROUND:
white">10:00</button></td>
<td><button type="button" value="M1030" id="M1030" style="BACKGROUND:
white">10:30</button></td>
<td><button type="button" value="M1100" id="M1100" style="BACKGROUND:
white">11:00</button></td>
<td><button type="button" value="M1130" id="M1130" style="BACKGROUND:
white">11:30</button></td>
<td><button type="button" value="M1200" id="M1200" style="BACKGROUND:
white">12:00</button></td>
<td><button type="button" value="M1230" id="M1230" style="BACKGROUND:
white">12:30</button></td>
<td><button type="button" value="M100" id="M100" style="BACKGROUND:
white">1:00</button></td>
<td><button type="button" value="M130" id="M130" style="BACKGROUND:
white">1:30</button></td>
<td><button type="button" value="M200" id="M200" style="BACKGROUND:
white">2:00</button></td>
<td><button type="button" value="M230" id="M230" style="BACKGROUND:
white">2:30</button></td>
<td><button type="button" value="M300" id="M300" style="BACKGROUND:
white">3:00</button></td>
<td><button type="button" value="M330" id="M330" style="BACKGROUND:
white">3:30</button></td>
<td><button type="button" value="M400" id="M400" style="BACKGROUND:
white">4:00</button></td>
<td><button type="button" value="M430" id="M430" style="BACKGROUND: whi
te">4:30</button></td>
</tr>

The ScheduleDay function displays the gets the value of a series of radio
buttons. The problem is that the value is a string corresponding to the ID
attribute of the button ( I have tried the name attribute to). I want to
use this string to change the background color of the button using a
function prototyped likeColorPeriodBtn(Btnname,Color). I am getting very
frustrated any help would be appreciated.
Jul 20 '05 #1
2 5673
If you are using Internet Explorer (5 onwards, I think), then you can use
the following...

function changeElement(strId) {
document.getElementById(strId).style = "background:yellow";
}

Alternatively, use a style sheet, then do...

function changeElement(strId) {
document.getElementById(strId).className = strYourClassName;
}

When passing values to the function containing the above you could use
changeElement(this.id) when passing from an event from the specific element
you wish to change.

Hope some of this ramble makes sense to you!

Peter.

"Charles Russell" <ce***@surewest.net> wrote in message
news:vh************@corp.supernews.com...
I am new to JavaScript and I am currently having a problem that I can find no clear solution to. I have a series of button contained in a row. These
rows are defined as follows:
<tr> <!--This is Mondays row -->
<td><button type="button" value="Monday" id="Monday" style="BACKGROUND: yellow" onclick='ScheduleDay("Monday")'>Monday</button></td>
<td><button type="button" value="M830" id="M830" style="BACKGROUND:
white">8:30</button></td>
<td><button type="button" value="M900" id="M900" style="BACKGROUND:
white">9:00</button></td>
<td><button type="button" value="M930" id="M930" style="BACKGROUND:
white">9:30</button></td>
<td><button type="button" value="M1000" id="M1000" style="BACKGROUND:
white">10:00</button></td>
<td><button type="button" value="M1030" id="M1030" style="BACKGROUND:
white">10:30</button></td>
<td><button type="button" value="M1100" id="M1100" style="BACKGROUND:
white">11:00</button></td>
<td><button type="button" value="M1130" id="M1130" style="BACKGROUND:
white">11:30</button></td>
<td><button type="button" value="M1200" id="M1200" style="BACKGROUND:
white">12:00</button></td>
<td><button type="button" value="M1230" id="M1230" style="BACKGROUND:
white">12:30</button></td>
<td><button type="button" value="M100" id="M100" style="BACKGROUND:
white">1:00</button></td>
<td><button type="button" value="M130" id="M130" style="BACKGROUND:
white">1:30</button></td>
<td><button type="button" value="M200" id="M200" style="BACKGROUND:
white">2:00</button></td>
<td><button type="button" value="M230" id="M230" style="BACKGROUND:
white">2:30</button></td>
<td><button type="button" value="M300" id="M300" style="BACKGROUND:
white">3:00</button></td>
<td><button type="button" value="M330" id="M330" style="BACKGROUND:
white">3:30</button></td>
<td><button type="button" value="M400" id="M400" style="BACKGROUND:
white">4:00</button></td>
<td><button type="button" value="M430" id="M430" style="BACKGROUND: whi te">4:30</button></td>
</tr>

The ScheduleDay function displays the gets the value of a series of radio
buttons. The problem is that the value is a string corresponding to the ID attribute of the button ( I have tried the name attribute to). I want to
use this string to change the background color of the button using a
function prototyped likeColorPeriodBtn(Btnname,Color). I am getting very
frustrated any help would be appreciated.

Jul 20 '05 #2
JRS: In article <KA******************@newsfep2-gui.server.ntli.net>,
seen in news:comp.lang.javascript, ManoDestra <manodestra.software@ntlwo
rld.com> posted at Tue, 22 Jul 2003 03:46:42 :-
If you are using Internet Explorer (5 onwards, I think), then you can use
the following...

function changeElement(strId) {
document.getElementById(strId).style = "background:yellow";
}

That's not right, under default assumptions.

It is OK if we assume that the only person reading the page is its
author (I have a few like that); but in the World-Wide Web, which is the
default assumption here, it is the reader's browser that matters, not
the author's. Many authors do not think of that.

The proportion who are using browsers compatible with IE5 is large, but
it is not unity.

Before answering here, you should read and understand the regularly-
posted FAQ, linked below; section 2.3 in particular.

Look at the posts in this group, ignoring yours and mine; you will see
that the more intelligent users predominantly comply with paragraph 5 of
2.3, and in particular sentence 6 thereof. Responses should follow
trimmed quotes.

Jim - FAQ 2.3 para 2 sentence 2 last word should be words.

--
© John Stockton, Surrey, UK. ?@merlyn.demon.co.uk Turnpike v4.00 IE 4 ©
<URL:http://jibbering.com/faq/> Jim Ley's FAQ for news:comp.lang.javascript
<URL:http://www.merlyn.demon.co.uk/js-index.htm> JS maths, dates, sources.
<URL:http://www.merlyn.demon.co.uk/> TP/BP/Delphi/JS/&c., FAQ topics, links.
Jul 20 '05 #3

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

Similar topics

6
by: Hameed Khan | last post by:
hi, i was reading library refrence manual. there i found object() function. they says in library refrence that "Return a new featureless object. object() is a base for all new style classes. It...
11
by: Grasshopper | last post by:
Hi, I am automating Access reports to PDF using PDF Writer 6.0. I've created a DTS package to run the reports and schedule a job to run this DTS package. If I PC Anywhere into the server on...
1
by: Prasad Karunakaran | last post by:
I am using the C# DirectoryEntry class to retrieve the Properties of an user object in the Active Directory. I need to get the First Name and Last Name as properties. I know it is not supported...
6
by: orahm | last post by:
I have started an earlier thread about this topic. I got some good info but I'm still confused. I'm trying to add a complex number object that contains a real and a imaninary double to a listbox....
5
by: ElanKathir | last post by:
Hi ! I wrote one code for Send the E-mail, But that code have some problem , So please help me Here i paste my code and Error: Error: Server Error in '/Elan_Sample' Application. ...
1
by: ratnakarp | last post by:
Hi, I have a search text box. The user enters the value in the text box and click on enter button. In code behind on button click i'm writing the code to get the values from the database and...
0
by: Peter Conrey | last post by:
I have a perl web service (using SOAP::Lite) with a method called "Detail" that returns a strucure (hash reference to be exact). It works fine when consumed by a Perl client, but when I try to...
1
by: John Rugo | last post by:
Hi All, I would like to know how to set an object from a string provided? Here is the situation: I have a listview that holds the names of ListView Objects on different forms. I want to set...
1
by: xnakxx | last post by:
for the sake of making my crazy question eaiser to understand i will try to simplify it as much as possible. Let's say I have a form with one textbox (txtname) and one button (bntGo). How would...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
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
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
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
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
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...

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.