Solved

HTML- PHP onClick Event Doesn't Work

Posted on 2015-02-03
6
132 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

 
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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Build an array called $myWeek which will hold the array elements Today, Yesterday and then builds up the rest of the week by the name of the day going back 1 week.   (CODE) (CODE) Then you just need to pass your date to the function. If i…
This article explains how to prepare an HTML email signature template file containing dynamic placeholders for users' Azure AD data. Furthermore, it explains how to use this file to remotely set up a department-wide email signature policy in Office …
In this tutorial viewers will learn how to embed videos in a webpage using HTML5. Ensure your DOCTYPE declaration is set to HTML5: "<!DOCTYPE html>": Use the <video> tag to insert a video. Define the src as the URL of your video; this is similar to …
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

739 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