dpvp56187 2011-08-04 22:06
浏览 32
已采纳

从AutoSuggest jQuery代码中分离jQuery CSV中的值

I am currently using - http://code.drewwilson.com/entry/autosuggest-jquery-plugin for an autosuggest on my site. I have limited the number of choices to 3.

This is the autosuggest code:

<script type="text/javascript">
$(document).ready(function() {
$("input[id=category]").autoSuggest("http://localhost:8888/bl/pages_mx/category_1.php",      
{selectedItemProp: "name", selectedValuesProp: "value", searchObjProps: "name", 
minChars: 1, matchCase: false, selectionLimit: 3});
});
</script>

The categories the visitor can choose is taken from a table within the MYSQL database. I can now successfully see the suggestions when I begin to type in potential categories!

The 2 values that are queried from the 'category' table are - category_ID and name.

My question is, once the user has chosen their 1,2 or 3 choices, how can I get the category_ID in 3 different variables in php, or in an array?

The closest I have got to help on their discussion forum is by using this code:

var arr = $(".as-values").val().split(",");

But from there, I have no idea how to implement this?

I have tried using an explode function to split the CSV using this:

<?php if($_POST['category_submit']){ ?>
<script type="text/javascript">
var arr = $(".as-values").val().split(",");
var exploded = arr.split(',');
var category_1=exploded[0];
var category_2=exploded[1];
var category_3=exploded[2];
print (category_1);
</script>
<?php } ?>

But nothing seems to print when I press submit?

Any help would be hugely appreciated.

Many thanks!

But nothing seems

  • 写回答

1条回答 默认 最新

  • drccfl9407 2011-08-04 22:49
    关注

    First, it's important to write JavaScript when writing JavaScript. "Print" is not a valid line of JavaScript.

    Second, when you call .split(), what you get is an array that's immediately indexable.

    var arr = $(".as-values").val().split(",");
    var category_1=arr[0];
    var category_2=arr[1];
    var category_3=arr[2];
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 mmocr的训练错误,结果全为0
  • ¥15 python的qt5界面
  • ¥15 无线电能传输系统MATLAB仿真问题
  • ¥50 如何用脚本实现输入法的热键设置
  • ¥20 我想使用一些网络协议或者部分协议也行,主要想实现类似于traceroute的一定步长内的路由拓扑功能
  • ¥30 深度学习,前后端连接
  • ¥15 孟德尔随机化结果不一致
  • ¥15 apm2.8飞控罗盘bad health,加速度计校准失败
  • ¥15 求解O-S方程的特征值问题给出边界层布拉休斯平行流的中性曲线
  • ¥15 谁有desed数据集呀