开发者

Problem in entering multiple E-Mail ID in A Single Field

Hi I had A field In Than i am enter the multiple e mail id using the automated dropdown . I refer this link "http://wick.sourcef开发者_C百科orge.net/wick_sample/" U get the Full view about my program in this link. In This all e-mail id's are stored in the variable collection. My problem is if i declare the E-mail id directly in the variable like This

var data = ['meena@gmail.com','raam@yahoo.com','priya@group.com','priya@group.com'];

collection = data; Its Working properly but i am retrieve the e-mail Id from the Database . so i am using below mentioned code but it does not work how i solve this issue .

function show_alert() {

    var id1 = document.getElementById('collection').value;


    var data = [id1];

    collection = data;


    alert(collection);
}

<?php

$table = "am_users";
$query = "select distinct(`user_email`) from $table";
$result = mysql_query($query);

$num_rows = mysql_num_rows($result);


while ($data1 = mysql_fetch_array($result)) {
    $data[] = $data1['user_email'];
}

foreach($data as $search_term) {
    $js_data[] = "/'".$search_term."/'";
}


$collection = implode($js_data, ",");


?>

<html>
    <head>

    </head>
    <body>

        <input type="text"  id="collection" name="collection" rows="5" cols="30" value="<?php echo $collection; ?>" onChange="show_alert()" />

    </body>
</html>

Please Guide me,have a nice day to every one


hi meena

One problem i notice is , you have event fire on change, ie when you change content in box or modify it, so you will not get expected result in that case.

What i have did is , onfucus , i have set value and on change you can see the setvalue.

Try this, keep simple and clean

<?
  $query = "select DISTINCT user_email from am_users";
  $result = mysql_query($query);
  $rows = mysql_fetch_array($result);
  foreach($rows as $row){
    $data[] = trim($row['user_email']);
  }
  $collection = implode($data, ",");
?>


<html>
    <head>
      <script>
      var collection="";
      function show_alert() {
          alert(collection);
      }
      function set_value(){
        collection = document.getElementById('collection').value;
      }
      </script>
    </head>
    <body>
      <input type="text"  id="collection" name="collection" rows="5" cols="30" value="<?php echo $collection; ?>" onFocus="set_value()" onChange="show_alert()" />
    </body>
</html>
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜