谁能帮我从jquery中获取变量并在php中使用 [英] can any one help to me to get variable from jquery and use in php
问题描述
当我选择生产者类型onchange时,我现在有了选择列表,我希望从jquery获得生产者类型值,并且我想用php isset(producertype)作为角色并将角色类型分别更改为
i have fllowing select list now when i select producertype onchange i want producerType value from jquery and i want to isset(producertype) with php for role and change the role type respectively as
<select id="ProducerType" name="ProducerType" style="float:left;">
<option value="Principal">Principal</option>
<option value="Producer">Producer</option>
<option value="SoleProprietor">Sole Proprietor</option>
</select>
<select id="ProducerType" name="ProducerType" style="float:left;">
<option value="Principal">Principal</option>
<option value="Producer">Producer</option>
<option value="SoleProprietor">Sole Proprietor</option>
</select>
<select id="Role" name="Role" style="float:left;">
<option value="">Agent</option>
</select>
<select id="Role" name="Role" style="float:left;">
<option value="">Agent</option>
</select>
推荐答案
我理解这个问题,答案将很复杂. 首先,您需要将onChange事件添加到ProducerType选择框中. 在您的html末尾添加此代码:
I understand the question and the answer is going to be complex. First you need to add onChange event to your ProducerType selectbox. Add this at the end of your html:
<script>
$(document).ready(function(){
// attach event on change
$('#ProducerType').on('change',function(){
// call script on server to check if isset() and receive values for Role
$.get("checkproducer.php?ProducerType="+$('#ProducerType').val(),function(result){
// here the script on server returned data already
// update Role selectbox with new values
$('#Role').html(result)
})
})
})
</script>
确保照常加载了jquery.js.
Make sure you have jquery.js loaded as usual.
您将需要在服务器上创建一个PHP脚本来处理检查并为您选择的输入返回新数据.像这样(另存为"checkproducer.php"):
You will need to create a PHP script on server which handles the check and returns new data for your select input. Like this (save as "checkproducer.php"):
<?php
if ($_GET['ProducerType']=="Principal")
echo "<option value=1>Principal1</option>"
."<option value=2>Principal2</option>";
if ($_GET['ProducerType']=="Producer")
echo "<option value=1>Producer1</option>".
."<option value=2>Producer2</option>";
if ($_GET['ProducerType']=="SoleProprietor")
echo "<option value=1>SoleProprietor1</option>"
."<option value=2>SoleProprietor2</option>";
// etc
?>
这篇关于谁能帮我从jquery中获取变量并在php中使用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!