Programming Tools
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
User Name:
Password:
Remember me
 
Go Back   Dev Articles Community ForumsProgrammingProgramming Tools

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Display Modes
 
Unread Dev Articles Community Forums Sponsor:
  #1  
Old November 12th, 2002, 05:54 PM
fakker fakker is offline
The calm b4 the storm
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jul 2002
Location: Manchester, UK
Posts: 404 fakker User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 7
Send a message via Yahoo to fakker
Javascript style using variables..

hi,

I have the following Javascript function:

Code:
function change(toStatus,row)
{
  if (toStatus == 'ON') 
  {
   row.style.backgroundColor = "#D7FFD2";
  }
  
  if (toStatus == 'OFF') 
  {
   row.style.backgroundColor = "#E1E1E1";	
  }


I call the funtion using radio buttons... so in row1, the radio button would look like:

<input type=radio name=anything value=ON checked onClick="change('ON','$row');">

so.... when the user clicks the radio button it calls "change" and passed the $row number (this is generated in PHP and all works ok..)

all I need to know is... in the JS function, how can I tell it that ROW is a variable.. at the moment, the bit of code "row.style.backgroundColor" is looking for the row with the ID "row" when it should be looking for the row with the ID passed in the function variable....

eg: in PHP youd use $row.style...... is there something similar in JS???

Cheers.
__________________
Matt 'Fakker' Facer

mattfacer.com

Reply With Quote
  #2  
Old November 12th, 2002, 06:55 PM
Nigorr Nigorr is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Apr 2002
Location: Brisbane, Australia
Posts: 78 Nigorr User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 7
Hi, could you give me the whole html page, then I can help you, I have done this before but can't find it.

by giving me the whole html page saves me time try to make one up

Reply With Quote
  #3  
Old November 12th, 2002, 07:09 PM
fakker fakker is offline
The calm b4 the storm
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jul 2002
Location: Manchester, UK
Posts: 404 fakker User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 7
Send a message via Yahoo to fakker
sure...here u go.....


Code:
<html>
<head>
<script language="JavaScript">


function change(toStatus,row)
{
  
  if (toStatus == 'ON') 
  {
    row.style.backgroundColor = "#D7FFD2";
  }
  
  if (toStatus == 'OFF') 
  {
   row.style.backgroundColor = "#E1E1E1";
  }

}

</script>



</head>

<body>

<form action="update.php" method="post" name="form">
<input type="hidden" name="todo" value="update">
<table width="500" border="0" align="center" cellpadding="2" cellspacing="0">
  <tr> 
    <td width="176" class="table_head"><strong>Button Name</strong></td>
    <td width="162" class="table_head"> 
      <div align="center"><strong>ON</strong></div></td>
    <td width="162" class="table_head"> 
      <div align="center"><strong>OFF</strong></div></td>
  </tr>
<tr bgcolor="#E1E1E1" id="a">
<td class="table_row">button_name1</td>
<td class="table_row"><div align="center">
<input type="radio" name="button_name1" value="ON" onClick="change('ON','a');">
</div></td>
<td class="table_row"><div align="center">
<input type="radio" name="button_name1" value="OFF" checked onClick="change('OFF','a');">
</div></td>
</tr>

<tr bgcolor="#E1E1E1" id="b">
<td class="table_row">button_name2</td>
<td class="table_row"><div align="center">
<input type="radio" name="button_name2" value="ON" onClick="change('ON','b');">
</div></td>
<td class="table_row"><div align="center">
<input type="radio" name="button_name2" value="OFF" checked onClick="change('OFF','b');">
</div></td>
</tr>


</table>
<p align="center">
  <input name="Submit" type="submit" class="textbox" value="<<<< UPDATE BUTTONS >>>>">
</p></form>
</body>
</html>

Reply With Quote
  #4  
Old November 12th, 2002, 07:15 PM
fakker fakker is offline
The calm b4 the storm
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jul 2002
Location: Manchester, UK
Posts: 404 fakker User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 7
Send a message via Yahoo to fakker
so if the value of "row" is passed on as "a" ... the code in the JS function should work like:

a.style.backgroundColor = "#D7FFD2";

that works... when you actually put "a.style" but when you want to use the value from the function "function(toStatus,row)" it doesnt......

each row has an "id=a" tag..... so the first on is "id=a" then the next rown in the table is "id=b" etc etc....... that way the style change only affects the desired row...

Reply With Quote
  #5  
Old November 12th, 2002, 07:50 PM
Nigorr Nigorr is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Apr 2002
Location: Brisbane, Australia
Posts: 78 Nigorr User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 7
here is the working version

Code:
<html>
  <head>
    <script language="JavaScript">
      function change(toStatus,row) {
        if (toStatus == 'ON') {
          eval(row + ".style.backgroundColor = \"#D7FFD2\"");
        }
 
        if (toStatus == 'OFF') {
          eval(row + ".style.backgroundColor = \"#E1E1E1\"");
        }

      }
    </script>
  </head>

  <body>
    <form action="update.php" method="post" name="form">
      <input type="hidden" name="todo" value="update">
      <table width="500" border="0" align="center" cellpadding="2" cellspacing="0">
        <tr> 
          <td width="176" class="table_head"><strong>Button Name</strong></td>
          <td width="162" class="table_head"> 
            <div align="center"><strong>ON</strong></div>
          </td>
          <td width="162" class="table_head"> 
            <div align="center"><strong>OFF</strong></div>
          </td>
        </tr>
        <tr bgcolor="#E1E1E1" id="a">
          <td class="table_row">button_name1</td>
          <td class="table_row">
            <div align="center">
              <input type="radio" name="button_name1" value="ON" onClick="change('ON','a');">
            </div>
          </td>
          <td class="table_row">
            <div align="center">
              <input type="radio" name="button_name1" value="OFF" checked onClick="change('OFF','a');">
            </div>
          </td>
        </tr>
        <tr bgcolor="#E1E1E1" id="b">
          <td class="table_row">button_name2</td>
          <td class="table_row">
            <div align="center">
              <input type="radio" name="button_name2" value="ON" onClick="change('ON','b');">
            </div>
          </td>
          <td class="table_row">
            <div align="center">
              <input type="radio" name="button_name2" value="OFF" checked onClick="change('OFF','b');">
            </div>
          </td>
        </tr>
      </table>

      <p align="center">
         <input name="Submit" type="submit" class="textbox" value="<<<< UPDATE BUTTONS >>>>">
      </p>
    </form>
  </body>
</html>


Any questions or does this make sense?

Reply With Quote
  #6  
Old November 12th, 2002, 07:56 PM
fakker fakker is offline
The calm b4 the storm
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jul 2002
Location: Manchester, UK
Posts: 404 fakker User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 7
Send a message via Yahoo to fakker
aaaah mate, you are a star!!!

it works perfectly!!!

thanks v much!!


Reply With Quote
Reply

Viewing: Dev Articles Community ForumsProgrammingProgramming Tools > Javascript style using variables..


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 4 hosted by Hostway
Stay green...Green IT