JQUERY自动填充另一个选择输入的选择输入 [英] JQUERY to auto-populate a select input from another select input
问题描述
我从这段代码中获得courseID:
$ coursesOutput ='< option value =>< / option>';
while($ row = mysql_fetch_array($ result2)){
$ courseID = $ row ['courseID'];
$ courseName = $ row ['name'];
$ coursesOutput。='< option value ='。$ courseID。'>'。 $ courseName。 < /选项>;
}
我的php脚本如下(返回echo语句)
<?php
include(includes / connect.php);
$ courseID = mysql_real_escape_string($ _ GET ['courseID']);
$ sql =SELECT tee1,tee2,tee3,tee4,tee5 FROM courses WHERE courseID ='$ courseID'LIMIT 1;
$ result = mysql_query($ sql)或die(mysql_error());
while($ row = mysql_fetch_array($ result)){
$ tee1 = $ row ['tee1'];
$ tee2 = $ row ['tee2'];
$ tee3 = $ row ['tee3'];
$ tee4 = $ row ['tee4'];
$ tee5 = $ row ['tee5'];
}
$ teesOutput ='< option value ='。$ tee1。'>'。 $ tee1。 < /选项>;
if($ tee2!=){
$ teesOutput。='< option value =''。$ tee2。'>'。 $ tee2。 < /选项>;
if($ tee3!=){
$ teesOutput。='< option value =''。$ tee3。'>'。 $ tee3。 < /选项>;
}
if($ tee4!=){
$ teesOutput。='< option value =''。$ tee4。'>'。 $ tee4。 < /选项>;
}
if($ tee5!=){
$ teesOutput。='< option value =''。$ tee5。'>'。 $ tee5。 < /选项>;
}
echo''。 $ teesOutput。 ;
die();
?>
我没有收到任何ajax错误,但仍然没有填充我的tee选择器。
希望这会有所帮助,再一次我被这里的支持所淹没,令人难以置信!
结束编辑1
现在我一直无法将这个AJAX-JQUERY功能解决出来。它应该是一个很好的jQuery程序员的简单场所。
我希望能够在用户选择课程后自动填充我的T恤选择输入。这是一款高尔夫应用程序,课程有多种不同的T恤配色方案,因此每种颜色都是特定的课程。
到目前为止,我的破解代码是:
HTML
< form id =formAddScoreaction =addscore.phpenctype = multipart / form-datamethod =post>
< p class =profile_label>选择日期:< / p>
< input type =textid =datepickername =datepickerclass =score_input/>
< p class =profile_label>选择课程:< / p>
< select id =coursename =courseclass =score_inputonchange =populateTee(this.value)>
'。 $ coursesOutput。 '
< / select>
< p class =profile_label>选择Tee:< / p>
< / select>
< p class =profile_label>实际分数:< / p>
< input id =scorename =scoreclass =score_inputtype =textsize =10/>
< p class =profile_label> Score ESC(Equitable Stroke Control):< / p>
< input id =scoreESCname =scoreESCclass =score_inputtype =textsize =10/>
< br />
< input id =btnAddScorename =btnAddScoreclass =btn_scoretype =submitvalue =Add Score/>
< / form>
JQUERY
函数populateTee(courseID)
{
$ .ajax(
{
url:'includes / populate_tee.php?courseID ='+ courseID,
成功:函数(数据){
$(#tee)。html(data);
}
});
PHP
populate_tee.php script WORKS,所以我不会浪费你的时间,包括它。
我相当确定问题出在上面的JQUERY-AJAX脚本中。
>任何帮助都会很棒。
预先致谢。
courseID从哪里来?尝试将其记录到控制台中。
这是否有帮助?
函数populateTee(courseID){
$ .ajax({
url:'includes / populate_tee.php?courseID ='+ courseID,
success:function(data){
//假设您将第三方列表作为索引数组返回
var ops ='';
for(var i = 0; i< data.length; i ++){
ops + ='< option>'+ data [i] +'< / option> ';
}
$(#tee)。html(ops);
}
});
}
EDIT 1
I am getting courseID from this code:
$coursesOutput = '<option value=""></option>';
while($row = mysql_fetch_array($result2)){
$courseID = $row['courseID'];
$courseName = $row['name'];
$coursesOutput .= '<option value="' . $courseID . '">' . $courseName . '</option>';
}
My php script is as follows (returning an echo statement)
<?php
include ("includes/connect.php");
$courseID = mysql_real_escape_string($_GET['courseID']);
$sql = "SELECT tee1, tee2, tee3, tee4, tee5 FROM courses WHERE courseID='$courseID' LIMIT 1";
$result = mysql_query($sql) or die(mysql_error());
while($row = mysql_fetch_array($result)){
$tee1 = $row['tee1'];
$tee2 = $row['tee2'];
$tee3 = $row['tee3'];
$tee4 = $row['tee4'];
$tee5 = $row['tee5'];
}
$teesOutput = '<option value="' . $tee1 . '">' . $tee1 . '</option>';
if($tee2 != ""){
$teesOutput .= '<option value="' . $tee2 . '">' . $tee2 . '</option>';
}
if($tee3 != ""){
$teesOutput .= '<option value="' . $tee3 . '">' . $tee3 . '</option>';
}
if($tee4 != ""){
$teesOutput .= '<option value="' . $tee4 . '">' . $tee4 . '</option>';
}
if($tee5 != ""){
$teesOutput .= '<option value="' . $tee5 . '">' . $tee5 . '</option>';
}
echo '' . $teesOutput . '';
die();
?>
I am not getting any ajax errors but still nothing populating in my tee selector. Hope this helps, once again I am overwhelmed by the support here, unbelieveable!
End EDIT 1
I have been unable to figure this AJAX-JQUERY feature out for awhile now. It should be an easy spot for good jQuery programmers.
I want to be able to auto-populate my tee select input after a user selects their course. This is a golf app and courses have several different tee color schemes so each will be course specific.
So far my broken codes are:
HTML
<form id="formAddScore" action="addscore.php" enctype="multipart/form-data" method="post">
<p class="profile_label">Select Date:</p>
<input type="text" id="datepicker" name="datepicker" class="score_input" />
<p class="profile_label">Select Course:</p>
<select id="course" name="course" class="score_input" onchange="populateTee(this.value)">
' . $coursesOutput . '
</select>
<p class="profile_label">Select Tee:</p>
<select id="tee" name="tee" class="score_input">
</select>
<p class="profile_label">Actual Score:</p>
<input id="score" name="score" class="score_input" type="text" size="10" />
<p class="profile_label">Score ESC (Equitable Stroke Control):</p>
<input id="scoreESC" name="scoreESC" class="score_input" type="text" size="10" />
<br/>
<input id="btnAddScore" name="btnAddScore" class="btn_score" type="submit" value="Add Score" />
</form>
JQUERY
function populateTee(courseID)
{
$.ajax(
{
url: 'includes/populate_tee.php?courseID=' + courseID,
success: function(data) {
$("#tee").html(data);
}
});
}
PHP
populate_tee.php script WORKS, so I won't waste your time including it.
I am fairly certain the problem is in the above JQUERY-AJAX script.
Any help would be wonderful.
Thanks in advance.
Where does courseID come from? Try logging it into the console. Does this help?
function populateTee(courseID){
$.ajax({
url: 'includes/populate_tee.php?courseID=' + courseID,
success: function(data) {
//Assuming you're returning the tees list as an indexed array
var ops = '';
for(var i=0; i<data.length; i++){
ops += '<option>'+data[i]+'</option>';
}
$("#tee").html(ops);
}
});
}
这篇关于JQUERY自动填充另一个选择输入的选择输入的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!