Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

JAvaSCript Encapsulated to PHP

Posted on 2003-03-16
4
Medium Priority
?
282 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
2 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

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

Dramatic changes are revolutionizing how we build and use technology. Every company is automating, digitizing, and modernizing operations. We need a better, more connected way to work together as teams so we can harness the insights from our system…
When the s#!t hits the fan, you don’t have time to look up who’s on call, draft emails, call collaborators, or send text messages. An instant chat window is definitely the way to go, especially one like HipChat. HipChat is a true business app. An…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
Suggested Courses
Course of the Month14 days, 13 hours left to enroll

577 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