Take the 2-minute tour ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

I'm getting some problems trying to set order number if sequence of checkbox checked with javascript:

<?php
    for ($x=0; $x<count($UnidadesServicio); $x++){
        $idunidadserv = $UnidadesServicio[$x]['idunidadserv'];
        $unidadserv = utf8_encode($UnidadesServicio[$x]['lugarunidad']);
        $desunidad = utf8_encode($UnidadesServicio[$x]['desunidad']);
?>  

<tr>
  <td width="10%"><input type="checkbox" id="cbx_<?php echo $idunidadserv;?>" name="chk_unidadserv" value="<?php echo $idunidadserv;?>" onClick="AgregarUnidadServ()" /></td>

    <td width="56%" height="28"> <?php echo $unidadserv;?> </td>
    <td width="13%">&nbsp;</td>
  <td width="21%" align="center"> <input name="txt_orden_<?php echo $x;?>" type="text" id="txt_orden_<?php echo $idunidadserv;?>" value="" size="2" maxlength="1" class="txtorden" /> </td>

</tr>

<?php
    }
?>  

My JavaScript function:

<script>

function AgregarUnidadServ(){
   var group = document.getElementsByName('chk_unidadserv');
   var i;
   for (i=0; i<group.length; i++){
      if (group[i].checked == true){
         var id = parseFloat(i+1);
         $("#txt_orden_"+id).val(i);    
      }
   }
}

</script>

What i need to to do: enter image description here

When check any checkbox, set in input text the sequence number (1, 2, 3, etc.)

That code, display like this:

enter image description here

Greetings.

share|improve this question
    
and what error did you get? –  Eisa Adil Jan 13 at 21:14
    
I edited, sorry for bad english. –  Jhonatan Sandoval Jan 13 at 21:27
    
Are you using jQuery? –  Eisa Adil Jan 13 at 21:29
    
Where order number are storing? –  plutov.by Jan 13 at 21:31
add comment

1 Answer 1

$("#txt_orden_"+id).val(id);

And sequence will start from 1.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.