?
Solved

JAvaSCript Encapsulated to PHP

Posted on 2003-03-16
4
Medium Priority
?
274 Views
Last Modified: 2006-11-17
how can i write php with javascript code pls help..

sample idea like this..
<?php
$query = "SELECT stuff FROM mystuff ORDER BY stuff";
$result = mysql_query($query);
echo "<TABLE BORDER=\"0\" ONCLICK=\"Event()\">\n";
while($row = mysql_fetch_array($result)) {
    echo "<TR><TD>" . $row['stuff'] . "</TD></TR>\n";
}
echo "</TABLE>\n";
?>

i call javascript onclick event function, did i write it corretly? -->>ONCLICK=\"Event()\"

pls help..
0
Comment
Question by:chrisraymund
[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
4 Comments
 
LVL 1

Accepted Solution

by:
trojan2k earned 80 total points
ID: 8149910
Hi,

Change it to

onMouseDown=\"Event()\"

And you can test this in javascript easily

<script>
  function Event(){
    alert("Weee!");
  }
  var ln;
  var test='tum te tum te tum';
  ln = "<table border='0' onMouseDown=\"Event()\">";
  ln+= "<tr><td>"+ test +"</td></tr>";
  document.write(ln);
</script>

The difference is that onMouseDown defines a handler for the entire table, if you use onclick you have to write it for each element that you need to be clickable ... afaik

In your echo string you can use single quotes for your HTML attributes which makes it look neater but you have to use \" for the function related things, like my example above, its not entirely nessecery to use the \n either.
0
 
LVL 2

Expert Comment

by:communicate
ID: 8152075
another point to remember:
javascript is case sensitive. onClick can't be substituted for ONCLICK.
try that and see if your code works ;)
0

Featured Post

WordPress Tutorial 2: Terminology

An important part of learning any new piece of software is understanding the terminology it uses. Thankfully WordPress uses fairly simple names for everything that make it easy to start using the software.

Question has a verified solution.

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

Color can increase conversions, create feelings of warmth or even incite people to get behind a cause. If you want your website to really impact site visitors, then it is vital to consider the impact color has on them.
CTAs encourage people to do something specific to show interest in your company, product or service. Keep reading to learn why CTAs should always be thought of as extremely important, albeit small, sections of websites.
This video teaches users how to migrate an existing Wordpress website to a new domain.
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.

777 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