Solved

HTML- PHP onClick Event Doesn't Work

Posted on 2015-02-03
6
122 Views
Last Modified: 2015-02-10
Hi guys,

I'm using 'onClick' event in html & php but it doesn't work the way I need, actually, what I'm doing is a calendar so when people click on any day, the number of day is stored on a variable but when I echo the variable $diaseleccionado, always shows the last day, but not the day I clicked.

Please any ideas on this matter?

This is the part of code and it shows from day 1 to 31.
  //-------------------------------DIA 30 PARA DIBUJAR EL CALENDARIO
  if(substr("$dia30",0,1) == "N") {
    ?><TD height="30" ALIGN=center bgcolor="#666666">30</a></TD><?php
  }else{
    if(substr("$dia30",0,1) == "L") {
      ?><TD height="30" ALIGN=center bgcolor="#E1FFE1"><a href="#" onClick="<?php $diaseleccionado = 30; ?>">30</a></TD><?php
    }else{
      if(substr("$dia30",0,1) == "C") {
        $totalcitaxpordia = substr("$dia30",1);
        if ('$totalcitaxpordia' <= '$total_citas_por_dia') {
          ?><TD height="30" ALIGN=center bgcolor="#990000">30</a></TD><?php
        }else{
          ?><TD height="30" ALIGN=center bgcolor="#E1FFE1"><a href="#" onClick="<?php $diaseleccionado = 30; ?>">30</a></TD><?php
        }
      }
    }
  }
  //-------------------------------DIA 31 PARA DIBUJAR EL CALENDARIO
  if(substr("$dia31",0,1) == "N") {
    ?><TD height="30" ALIGN=center bgcolor="#666666">31</a></TD><?php
  }else{
    if(substr("$dia31",0,1) == "L") {
      ?><TD height="30" ALIGN=center bgcolor="#E1FFE1"><a href="#" onClick="<?php $diaseleccionado = 31; ?>">31</a></TD><?php
    }else{
      if(substr("$dia31",0,1) == "C") {
        $totalcitaxpordia = substr("$dia31",1);
        if ('$totalcitaxpordia' <= '$total_citas_por_dia') {
          ?><TD height="30" ALIGN=center bgcolor="#990000">31</a></TD><?php
        }else{
          ?><TD height="30" ALIGN=center bgcolor="#E1FFE1"><a href="#" onClick="<?php $diaseleccionado = 31; ?>">31</a></TD><?php
        }
      }
    }
  }
  ?> </TR>
  <TR> <?php
  ?> </TR>
</table> 
<table width="280" border="0" align="center">
  <tr>
    <td><div align="center">
      <input type="submit" name="Submit" value="Asignar horario">
    </div></td>
  </tr>
</table>
<?php
if(isset($_POST['Submit'])) {
echo "$diaseleccionado";
  ?>

Open in new window

0
Comment
Question by:elm9999
  • 3
  • 2
6 Comments
 
LVL 31

Accepted Solution

by:
Marco Gasi earned 250 total points
ID: 40587324
Php doesn't have any onclick event: just it doesn't exist. Php is a server side language and all its stuff happens on the server side.  The onclick event, on the contrary, is a client-side event and it happens in the browser: the langauge you have to use is javascript.
The easiest way to use javascript is jQuery. You have to learn something about, then you'll can use an ajax call which will pass the variable to a php script to process it.
A good book about jquery is this one: http://www.sitepoint.com/books/jquery2/ I absolutely recommend it.
0
 
LVL 83

Assisted Solution

by:Dave Baldwin
Dave Baldwin earned 250 total points
ID: 40587335
If you look at the 'onclick' values in the "View Source", I think you will find that they are blank, not even a value there.  'onclick' has to invoke a javascript statement or function.  Just a value is not enough in any case.
0
 

Author Comment

by:elm9999
ID: 40587366
Thank you guys,

:(
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 31

Expert Comment

by:Marco Gasi
ID: 40587412
Don't be sad: you'll learn a lot of interesting and magic things! :-)
0
 

Author Comment

by:elm9999
ID: 40599271
Thank you guys,

I already change the way to do that, because I had not to much time to fix the problem.

Thank you again.
0
 
LVL 31

Expert Comment

by:Marco Gasi
ID: 40601264
elm9999, I find surprising you have downgraded our answers: if Php has not an onclick event it's not up to us! Or do you think we should rewrite Php to make you happy? ;-)
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Have you tried to learn about Unicode, UTF-8, and multibyte text encoding and all the articles are just too "academic" or too technical? This article aims to make the whole topic easy for just about anyone to understand.
Not sure what the best email signature size is? Are you worried about email signature image size? Follow this best practice guide.
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…
Video by: Mark
This lesson goes over how to construct ordered and unordered lists and how to create hyperlinks.

920 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now