选择时,将值赋给php的文本框onchange [英] Assign value to textbox onchange of php while select

查看:104
本文介绍了选择时,将值赋给php的文本框onchange的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在慢慢理解PHP,但这一个让我难住。
我用PHP中的数据填充'select'HTML元素使用.....
while($ row = mysql_fetch_array($ result))
所有工作正常,我理解为什么。
我只是想在选择时填写页面上的其他文本框。
http://jsfiddle.net/TPE9r/5/但它不使用PHP。
这是我的代码的一部分...



pre $ while($ row = mysql_fetch_array($ result)){
echo'< option value ='',$ row ['ContactID'],'>',$ row ['ContactName'],' - ',$ row ['BusinessName'],
'< / option>';}

抱歉格式化 - ..
我已经使用类似JavaScript的小提琴,但我不能在文本框中显示$ row ['ContactName']或$ row ['BusinessName']]。我可以用一个普通的HTML选择来做到这一点,但不是当行在'while循环'时才能做到这一点。

最后,解决了这个问题一个 - 也许不是最好的方法,但它可以帮助别人。
我使用了: $(this).find(':selected')。data('id') ....在 onchange
并在循环中使用 data-attributes

<$ p $ ($ i = 0; $ i< count($ results); $ i ++){
echo'< option data-id =''。$ results [$ i ] ['ContactID'],''data-bn =''。$ results [$ i] ['BusinessName'],'>'。 $结果[$ i] [联系人姓名]。

< / option>;

和3个文本框,其ID为bb,cc,dd ....

  price2 = this.value; 
price1 = $(this).find(':selected')。data('id')
price3 = $(this).find(':selected')。data('bn')

$('#bb')。val(price1);
$('#cc')。val(price2);
$('#dd')。val(price3);

循环中的单引号和双引号有点棘手,但'嘿,那就是我们做的!

I'm slowly understanding PHP but this one has me stumped. I am populating a 'select' HTML element with data from PHP using..... while($row = mysql_fetch_array($result)) All is working fine and I understand why. I just wanted to fill in other textboxes on the page when a selection is made. There is a very helpful fiddle at http://jsfiddle.net/TPE9r/5/ but it does not use PHP. This is part of my code...

while($row = mysql_fetch_array($result)){
    echo '<option value=" ',$row['ContactID'],' ">', $row['ContactName'],' -- ',    $row['BusinessName'],
'</option>';}

Sorry about the formatting - new on here also... I have used similar JavaScript to the fiddle but I can't display $row['ContactName'] or $row['BusinessName'] in a textbox. I can do this with a normal HTML select but not when the rows are in a 'while loop'

解决方案

Finally, solved this one - maybe not the best way but it may help others. I used : $(this).find(':selected').data('id') .... in the onchange and used data-attributes in the loop

for($i=0;$i < count($results); $i++) {
echo '<option data-id="'.$results[$i]['ContactID'],' " data-bn="'.$results[$i]['BusinessName'],' " >'. $results[$i]['ContactName']. 

"</option>";

and 3 textboxes whose id is bb, cc, dd ....

price2= this.value;
price1 = $(this).find(':selected').data('id')
price3 = $(this).find(':selected').data('bn')

$('#bb').val(price1);
$('#cc').val(price2);
$('#dd').val(price3);

Just a bit tricky with single and double quotes in the loop but 'Hey that's what we do!'

这篇关于选择时,将值赋给php的文本框onchange的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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