admin管理员组文章数量:1356294
As you see I have class whose name is table; and I have many functions on it "mainface" is one of them; these function is like my interface there are some check box and bobox on it; I want to write some JavaScript on "All" checkbox -> onclick=" "
.
I want that when the user click on the "All" checkbox and option will disappear on the screen but I cannot find a way to do it.
Is there any way to do it ? Can I add call the JavaScript function to onclick?
<script type="text/javascript" >
function hide(){
if(document.form.All.checked){
document.getElementById('option').style.visibility="hidden";
}
}
</script>
</head>
<body>
<?php
class table{
public function __construct() {
echo table:: mainface();
}
public function mainface()
{
$arayuz=" ";
$arayuz.="<form name=form action=index.php method=post>";
$arayuz.="<fieldset>";
$arayuz.="<input type=checkbox name=All value=All onclick='SOME JAVA SCRIPT FUNCTION'>;
}
?>
As you see I have class whose name is table; and I have many functions on it "mainface" is one of them; these function is like my interface there are some check box and bobox on it; I want to write some JavaScript on "All" checkbox -> onclick=" "
.
I want that when the user click on the "All" checkbox and option will disappear on the screen but I cannot find a way to do it.
Is there any way to do it ? Can I add call the JavaScript function to onclick?
<script type="text/javascript" >
function hide(){
if(document.form.All.checked){
document.getElementById('option').style.visibility="hidden";
}
}
</script>
</head>
<body>
<?php
class table{
public function __construct() {
echo table:: mainface();
}
public function mainface()
{
$arayuz=" ";
$arayuz.="<form name=form action=index.php method=post>";
$arayuz.="<fieldset>";
$arayuz.="<input type=checkbox name=All value=All onclick='SOME JAVA SCRIPT FUNCTION'>;
}
?>
Share
Improve this question
edited Dec 16, 2013 at 10:01
BenMorel
36.7k52 gold badges206 silver badges337 bronze badges
asked Jul 1, 2011 at 8:47
bluedoorbluedoor
452 silver badges7 bronze badges
4
- Although this may look like a duplicate of stackoverflow./questions/6545167/…, it's not, the older question was edited after it got closed. – user456814 Commented Jul 1, 2011 at 8:51
- Yes it is duplicate my older one is seems to very confuse ;now ı make clear my questions and make mmnet on it tobe understandable – bluedoor Commented Jul 1, 2011 at 8:55
- LAmureTJ: Write your HTML and Javascript first: this is what the browser sees. Then, write your PHP around it: this is pre-processed and helps you to automatically generate your HTML and Javascript; at this stage, do not touch your HTML or Javascript. – Lightness Races in Orbit Commented Jul 1, 2011 at 9:30
- That's looking much better now – Henry Commented Jul 1, 2011 at 9:50
4 Answers
Reset to default 3php file:
public function mainface()
{
$output = "<script type=\"text/javascript\" src=\"/path_to_your_js/table.js\">-</script>";
$output.= "<form name =\"form\" action=\"index.php\" method=\"POST\">";
$output.= "<fieldset>";
$output.= "<input type=\"checkbox\" name=\"ALL\" value=\"ALL\" onclick=\"checkAll(this)\">";
}
And then in table.js:
function checkAll( myCheckBox )
{
//do some stuff you need here
myCheckBox.style.display = "none";
}
I hope that helps...
You are mixing server side and client side script languages. PHP runs server side (on the web server), javascript runs client side (within the web browser). Onclick is javascript, so runs client side. You cannot call PHP functions directly from an Onclick action.
http://en.wikipedia/wiki/Client-side_scripting
http://en.wikipedia/wiki/Server-side
To achieve what you want you don't need any PHP scripting. It can all be done in Javascript. You'll need to add an ID to your form like this:
$arayuz.="<form name='form' id='myform' action='index.php' method='post'>";
Then use the following as the onclick action:
$arayuz.="<input type=checkbox name=All value=All onclick='document.getElementById(\"myform\").style.visibility = \"hidden\";'>"
That would work but printing out in-line JavaScript like that is hideous, I would really remend you look into unobtrusive JavaScript and use something like jQuery. Jquery example that would work for all checkbox's:
$(":checkbox").live('click' , function () {
$("#IdOfForm").hide();
});
form id is used in onclick
$arayuz.="<form name='form' id='form1' action='index.php' method='post'>";
this will be your onclick
$arayuz.="<input type=checkbox name=All value=All onclick='document.getElementById(\"form1\").style.visibility = \"hidden\";'>"
本文标签: How to use javascript in PHP class functionsStack Overflow
版权声明:本文标题:How to use javascript in PHP class functions? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744038632a2580247.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论