SitePoint Sponsor

User Tag List

Results 1 to 3 of 3

Thread: Help Please....

  1. #1
    SitePoint Member
    Join Date
    Jul 2005
    Posts
    19
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Help Please....

    I know what I want to acheive, but I lack the programming skills to put it together, the syntax, basic rules of javascript.
    Basically I have a table,
    when a user clicks a <tr> I would like to store a string variable (url),
    then when the user clicks a certain button on the page I would like to send them to the page associate with the row that has last been clicked (it stays highlighted). I know this is relatively simple to do, but I don't know how to do it.
    Please help!?

  2. #2
    Put your best practices away. The New Guy's Avatar
    Join Date
    Sep 2002
    Location
    Canada
    Posts
    2,087
    Mentioned
    1 Post(s)
    Tagged
    1 Thread(s)
    This is a little messy but it should show you how it could be down. You should be able to expand from there.

    Code:
     <html>
     <script>
     function TouchIt(location,id){
     	
     	var cells = new Array();
     	cells[0] = 't1';
     	cells[1] = 't2';
     	
     	for (i=0;i<cells.length;i++)
     	{
     		if (document.getElementById(cells[i])){
     			document.getElementById(cells[i]).style.backgroundColor = "darkred";
     		}
     	}
     	
     	document.getElementById(id).style.backgroundColor = "#FDBD78";
     	document.getElementById('MyForm').action = location;
     }
     </script>
     <style type="text/css">
     #t1 {
     	display: block;
     	background-color: darkred;
     	color: white;
     	cursor: pointer;
     }
     #t2 {
     	display: block;
     	background-color: darkred;
     	color: white;
     	cursor: pointer;
     }
     </style>
     <body>
     <table>
     	<tr>
     		<td id="t1" onclick="TouchIt('http://www.yahoo.com','t1');">Touch Me!</td>
     	</tr>
     	<tr>
     		<td id="t2" onclick="TouchIt('http://www.google.com','t2');">No Touch Me!</td>
     	</tr>
     </table>
     <br />
     <form id="MyForm" action="#">
     	<input type="submit" value="Go Touching!" />
     </form>
     </body>
     </html>
    "A nerd who gets contacts
    and a trendy hair cut is still a nerd"

    - Stephen Colbert on Apple Users

  3. #3
    SitePoint Member
    Join Date
    Jul 2005
    Posts
    19
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    That works, only

    That works great, only I have alternating colored rows,
    I tried adding an else statement but it doesnt work at all now,
    I can't figure out what I'm doing wrong....
    I really appreciate your help with this, or anyone who can help me.

    Code:
      <script>
     function TouchIt(location,id){
     	
     	var cells = new Array();
     	cells[0] = 'doc1';
     	cells[1] = 'doc2';
     	
     	for (i=0;i<cells.length;i++)
     	{
     		if (document.getElementById(cells[i]).style.backgroundColor == "white"){
     			document.getElementById(cells[i]).style.backgroundColor = "white";
     		} else {
    			document.getElementById(cells[i]).style.backgroundColor = "#e6e6e6";
    	}
     	
     	document.getElementById(id).style.backgroundColor = "#FDBD78";
     	document.getElementById('MyForm').action = location;
     }
     </script>
    Last edited by tisha_aymond; Nov 11, 2005 at 10:18. Reason: Update Code


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •