Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

HTML- PHP onClick Event Doesn't Work

Posted on 2015-02-03
6
Medium Priority
?
137 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 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
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
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

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

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 an audio file in a webpage using HTML5. Ensure your DOCTYPE declaration is set to HTML5: : The declaration should display (CODE) HTML5 is supported by the most recent versions of all major browsers…
The viewer will learn how to count occurrences of each item in an array.
Suggested Courses

972 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