-1

I know i made lots of mistake thats why I come to here. Actually I have some data

According to data I have Indication 1, Indication 2, Indication 3 and Indication 4, for each indication there is some message for user and if I select 2, 3 or 4 then the message will move to that corrosponding indication. And really I dont have idea how to do it becouse these message are coming from dynamicaly as:

 $i=1;
      while($row=mysqli_fetch_array($qry))
      {
     ?>

      <div class="solo"><div style=" width:100px;height:24px;float:left;padding:4px ;">


        <select style="width:60px;font-size:14px;" onchange="move(this.value);">

          <option value="1">1</option>
          <option value="2">2</option>
          <option value="3">3</option>
          <option value="4">4</option>
          <!--<option value="60min">60min</option>
          <option value="other">other</option>-->
        </select>
      </div>

      <div style=" width:600px;height:24px;float:left;padding-top:8px;text-align:center;"> <?php echo $row['message'];?></div>
      <div  style=" width:100px;height:24px;float:left;padding:4px ;">
        <div style="width:100px; float:left;">
          <input style="float:left;" type="checkbox" value="<?php echo $row['id']; ?>" id="<?php echo $row['id']; ?>" name="foo[]"/><div style="padding:2px; float:left;"><a href="delete.php?q=<?php echo $row['id']; ?>" onclick="return del();">Kill</a></div>

        </div>

and I am using to get these message id

<script type="text/javascript">
function move(str)
{

var a=document.getElementsByClassName("mid")[0].value;
alert(a);
}
</script>

and i display this message id as in hidden text box:

<input type="hidden" name="msg" class="mid" value="<?php echo $row['id']; ?>">

am just confuse how to get a particuler message id for each message becouse above move() function is only giving one id by [0]

So I just want to know how to do this for each element when all the input box have same class.

2 Answers2

0

document.getElementsByClassName("mid") gives you an array of dom elements. You are currently taking only the first element in that array. So loop through it and get each ones value attribute

function move(str) {

  var a=document.getElementsByClassName("mid");
  for(var i=0;i<a.length;i++)
     alert(a[i].value);

}

update

Its not clear what you are trying to achieve. If you are trying to alert the value of dom element with index as str, then the function could be as simple as

function move(str) {

  alert(document.getElementsByClassName("mid")[str].value);

}

if not please mention what you are trying to achieve in your question.

Mithun Satheesh
  • 27,240
  • 14
  • 77
  • 101
  • it working fine....but you know i just want to alert all different only once but this is giving all dom element value for one onchange... – user2753306 Sep 07 '13 at 08:25
0

If i understand correctly you want to iterate over the result list of getElementByClassName.

For this have a look at: https://stackoverflow.com/a/15843940/1885950

In your case it will look like:

var mid_holders = document.getElementsByClassName("mid");
for(var i = 0; i < mid_holders.length; i++)
{
    alert(mid_holders.item(i).value);
}
Community
  • 1
  • 1
mrcrgl
  • 640
  • 4
  • 11