i'm totally bugged from this problem... i need to know how to rewrite this PHP code, into jquery so we are making the check and going over the foreach method on other event, here is the code:
<?php
$aTc = array("c++", "java", "php", "coldfusion", "javascript", "asp", "ruby", "python", "c", "scala", "groovy", "haskell", "perl");
if($_POST['formSubmit']) {
if(!$tags = $_POST['item']) {
开发者_StackOverflow exit ;
}
foreach($tags[tags] as $ko) {
if(in_array($ko, $aTc)) {
$ra .= "$ko ";
}
}
echo "$ra";
}
?>
Uhh... so I have almost no idea what you're trying to achieve here, but here's something.
var languages = ["c++", "java", "php", "coldfusion", "javascript", "asp", "ruby", "python", "c", "scala", "groovy", "haskell", "perl"];
var list = "";
var selected = $('#languages').val() || [];
$.each(selected, function(index, language) {
if ($.inArray(language, languages) {
list.concat(language + " ");
}
});
alert(list);
This assumes that there is a multi-select drop-down field with the ID "languages", where the option values are the language names.
精彩评论