将值从javascript传递给PHP(隐藏字段) [英] Passing value from javascript to PHP ( Hidden Field )

查看:83
本文介绍了将值从javascript传递给PHP(隐藏字段)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

请举例说明通过隐藏字段将值从javascript传递到PHP的示例?

谢谢。



我正在尝试传递来自body.php的值



Can you please give me example of passing value from javascript to PHP through hidden field?
Thanks.

I'm trying to pass the value from body.php

<html>
<head><script type="text/javascript" src="../js/script.js"></script</head>
<body>
<form name="myform" method="post"
 önSubmit="return validateRadio()" action="">

<table class="tftable" border="1">
<tr><th><div align="center" class="tftable th">Questions</div></th><th colspan="2"><div align="center">Answer</div></th>
</tr>
<tr>
  <td>I like to dance</td>
  <td>
  <label></label>
  <label>
  <input name="bm1" type="radio" value="1" />
  Yes</label>
</td>
<td>
<label></label>
<label>
<input name="bm1" type="radio" value="2" />
No
</label>
</td></table></form>

<?php
if (isset($_GET['myval']))
{
echo "VALUE PASSED  : ".$_GET['myval']."<br>";
}
?>
</body>
</html>





这里是script.js



Here's script.js

function validateRadio()
{
// get all the inputs type
var inputs = myform.elements;
var radios = [];

// find the radio type
for (var i = 0; i < inputs.length; ++i) {
if (inputs[i].type == 'radio') {
radios.push(inputs[i]);
}
}
var countChecked = 0;
for (var j = 0; j < radios.length; j++) {
if (radios[j].checked) {
countChecked++;
}
}
//count number of radio button with value=1
var answeramount = 0;
for (var k = 0; k < radios.length; k++){
if(radios[k].checked && radios[k].value==1){
answeramount++;
}
}
if (countChecked != radios.length / 2){
alert("All questions must be answered.");
return false; // abort submit
} else {
 window.location.href = "body.php?myval=" + answeramount;
return true; // proceed to submit
} 
}





回音VALUE PASSED:。$ _ GET ['myval']不起作用......

请帮忙.. 。



The echo "VALUE PASSED : ".$_GET['myval'] doesn't work...
Please help...

推荐答案

_GET [' myval']))
{
echo VALUE PASSED:
_GET['myval'])) { echo "VALUE PASSED : ".


_GET [' myval']。 < br>;
}
?>
< / body >
< / html >
_GET['myval']."<br>"; } ?> </body> </html>





这里是script.js



Here's script.js

function validateRadio()
{
// get all the inputs type
var inputs = myform.elements;
var radios = [];

// find the radio type
for (var i = 0; i < inputs.length; ++i) {
if (inputs[i].type == 'radio') {
radios.push(inputs[i]);
}
}
var countChecked = 0;
for (var j = 0; j < radios.length; j++) {
if (radios[j].checked) {
countChecked++;
}
}
//count number of radio button with value=1
var answeramount = 0;
for (var k = 0; k < radios.length; k++){
if(radios[k].checked && radios[k].value==1){
answeramount++;
}
}
if (countChecked != radios.length / 2){
alert("All questions must be answered.");
return false; // abort submit
} else {
 window.location.href = "body.php?myval=" + answeramount;
return true; // proceed to submit
} 
}





回音VALUE PASSED:。



The echo "VALUE PASSED : ".


_GET ['myval']无效......

请帮忙......
_GET['myval'] doesn't work...
Please help...


这篇关于将值从javascript传递给PHP(隐藏字段)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆