Solved

HTML- PHP onClick Event Doesn't Work

Posted on 2015-02-03
6
121 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 30

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 82

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
Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 
LVL 30

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 30

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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Suggested Solutions

Developers of all skill levels should learn to use current best practices when developing websites. However many developers, new and old, fall into the trap of using deprecated features because this is what so many tutorials and books tell them to u…
This article discusses how to create an extensible mechanism for linked drop downs.
The viewer will learn how to dynamically set the form action using jQuery.
HTML5 has deprecated a few of the older ways of showing media as well as offering up a new way to create games and animations. Audio, video, and canvas are just a few of the adjustments made between XHTML and HTML5. As we learned in our last micr…

747 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

15 Experts available now in Live!

Get 1:1 Help Now