0

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']) {
                            exit ;
                    }
                    foreach($tags[tags] as $ko) {
                            if(in_array($ko, $aTc)) {
                                    $ra .= "$ko ";
                            }
                    }
                    echo "$ra";
            }
            ?>
4
  • 1
    why are you using assignment = operator in if if(!$tags = $_POST['item']) Commented May 14, 2011 at 4:40
  • what do u want achieve with this code Commented May 14, 2011 at 4:41
  • I'm assuming he wants to check if it's null, then exit? Not sure... Commented May 14, 2011 at 4:50
  • I want to check if the value which is submited is found into array then to be displayed, if not...value should not show Commented May 14, 2011 at 4:58

1 Answer 1

1

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.

Sign up to request clarification or add additional context in comments.

1 Comment

thank you for your answer, it cover almost everything i needed :)

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.