选择时,将值赋给php的文本框onchange [英] Assign value to textbox onchange of php while select
问题描述
我正在慢慢理解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屋!