d2jsp
Log InRegister
d2jsp Forums > Off-Topic > Computers & IT > Programming & Development > Function Question
Prev12
Add Reply New Topic New Poll
Member
Posts: 827
Joined: Jan 16 2012
Gold: 0.00
Warn: 10%
Sep 12 2012 02:37pm
actually, thinking it through now, forget about the edit2 part, it wont help you, I don't know if you can do something like "while mouseover do that" and etc. My best would be to work with hidden fields and both the OnMouseOver and OnMouseOut event. On the onmouseover event, you would save the ID of the cell in a hidden field, and if someone press the correct key to change the color, it would read the cell that was saved in the hidden field, and when the OnMouseOut is called, you would clean this hidden field, so nothing would happen when pressing the key. I'll make some sample code later to explain better.
Member
Posts: 827
Joined: Jan 16 2012
Gold: 0.00
Warn: 10%
Sep 12 2012 03:51pm
I ended up making it, hope it helps you understand.

Code


<!DOCTYPE html>
<html>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.1/jquery.min.js" type="text/javascript"></script>
<HEAD>
 <TITLE>Change BG color on click</TITLE>
</HEAD>
<BODY>
 <h1 align="center">Press "R" for Red and "B" for Blue</h1>
 
 <table width="100%" border="1px" cellspacing="0px" bgcolor="#FFFFFF">
  <thead>
   <tr>
    <th>Name</th>
    <th>Age</th>
   </tr>
  </thead>
  <tbody>
   <tr>
    <td>John</td>
    <td>25</td>
   <tr>
   <tr>
    <td>James</td>
    <td>27</td>
   <tr>
  </tbody>
 </table>
</body>
<script type="text/javascript">
 $(function(){
  var cont = 0;
  var cell;
 
  $("table").find("td").each(function() {
   $(this).css({"text-align" :"center"});
   $(this).attr("id", "tdCell" + cont);
   cont++;
  });
 
  $("td").bind('mouseover', function () {
   cell = "#" + $(this).attr("id");
  });
 
  $("td").bind('mouseout', function () {
   cell = "";
  });
 
  $("body").bind('keydown', function (event) {
   if (event.which == 82) {
    $(cell).css({"background-color" :"red"});
   }
   if (event.which == 66){
    $(cell).css({"background-color" :"blue"});
   }
  });
 });
</script>
</html>



Member
Posts: 18,732
Joined: Sep 3 2008
Gold: 0.00
Sep 12 2012 10:01pm
Quote (StormHasHe @ 12 Sep 2012 16:51)
I ended up making it, hope it helps you understand.

Code
<!DOCTYPE html>
<html>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.1/jquery.min.js" type="text/javascript"></script>
<HEAD>
 <TITLE>Change BG color on click</TITLE>
</HEAD>
<BODY>
 <h1 align="center">Press "R" for Red and "B" for Blue</h1>
 
 <table width="100%" border="1px" cellspacing="0px" bgcolor="#FFFFFF">
  <thead>
   <tr>
    <th>Name</th>
    <th>Age</th>
   </tr>
  </thead>
  <tbody>
   <tr>
    <td>John</td>
    <td>25</td>
   <tr>
   <tr>
    <td>James</td>
    <td>27</td>
   <tr>
  </tbody>
 </table>
</body>
<script type="text/javascript">
 $(function(){
  var cont = 0;
  var cell;
 
  $("table").find("td").each(function() {
   $(this).css({"text-align" :"center"});
   $(this).attr("id", "tdCell" + cont);
   cont++;
  });
 
  $("td").bind('mouseover', function () {
   cell = "#" + $(this).attr("id");
  });
 
  $("td").bind('mouseout', function () {
   cell = "";
  });
 
  $("body").bind('keydown', function (event) {
   if (event.which == 82) {
    $(cell).css({"background-color" :"red"});
   }
   if (event.which == 66){
    $(cell).css({"background-color" :"blue"});
   }
  });
 });
</script>
</html>


ok thanks, i will check it tomorow i just got out of work and im tired as fkkkkk!!!

btw is this html 5 ? the function? or php? because i saw a lot of $ in php if i remember correctly..
Member
Posts: 827
Joined: Jan 16 2012
Gold: 0.00
Warn: 10%
Sep 13 2012 07:47am
Nop, its pure HTML, this dollar sign is the alias used to call JQuery, in this context, as you can see in the script call:

Code

<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.1/jquery.min.js" type="text/javascript"></script>


JQuery is just a javascript library. http://jquery.com/
Go Back To Programming & Development Topic List
Prev12
Add Reply New Topic New Poll