Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

HTML- PHP onClick Event Doesn't Work

Posted on 2015-02-03
6
Medium Priority
?
134 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 750 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 84

Assisted Solution

by:Dave Baldwin
Dave Baldwin earned 750 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
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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

Important Lessons on Recovering from Petya

In their most recent webinar, Skyport Systems explores ways to isolate and protect critical databases to keep the core of your company safe from harm.

Question has a verified solution.

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

Today, the web development industry is booming, and many people consider it to be their vocation. The question you may be asking yourself is – how do I become a web developer?
When crafting your “Why Us” page, there are a plethora of pitfalls to avoid. Follow these five tips, and you’ll be well on your way to creating an effective page.
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 …
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)

688 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