0

I want to change the css of my textbox and to disabled the submit button in a php loop if it meets certain condiion .

I've successfully manage to loop the data through php but only the first textbox is changed

I'll put a few part of the php codes as php part is already done succesfully

Script

<style type="text/css">
.first
{
  color:#0C0
}
.second
{
   color:#F00
}

</style>

 <script src="js/jquery-1.8.3.js"></script>
 <script src="js/jquery-ui.js" > </script>
 <script> var $j = jQuery.noConflict();

 function changeClass(str)
 {
      if ($j('#status').val()== "No")
      {
          $j('#status').addClass('first');
      }
  else
  {
         $j('#status').removeClass('first');                                
         $j('#status').addClass('second');                   
         $j('#submit').prop('disabled', true);
       }              
return true;
 }
  </script>

HTML

 <table width="800" border="0" align="center" bordercolor="#000000" 
          onmousemove="changeClass(this);"> 
 <?php do { ?>
     <tr bgcolor="#FFFFCC">
       <th  align="center" bgcolor="#3366FF" class="style68" >Status</th>
       <th  align="center" bgcolor="#3366FF" class="style68" >Submit</th>
       <td  align="center" bgcolor="#CCCCCC">
          <form  > <input type="text"  id="status" name="status" 
           value="<?php echo$data['status']; ?>" >
       </td> 
       <td  align="center" bgcolor="#CCCCCC">
         <button id="submit" name="submit" type="submit" > Submit</button>
    </form>
   </td>
         </td>
                 </tr>   
                  <?php } while ($data = mysql_fetch_assoc($re)); ?>
                </table>
6
  • how many elements are there with id 'status'?, I mean is it repeating too? Commented Feb 14, 2013 at 8:40
  • the textbox with id="status" will be repeated. Commented Feb 14, 2013 at 8:50
  • 1
    Thats the problem you cant use same id for multiple elements.Thats the problem you cant use same id for multiple elements. If you want to change the style of all you have to use the same class for all elements. Commented Feb 14, 2013 at 8:51
  • Perhaps you should give it the same class and have an incrementing id. Commented Feb 14, 2013 at 8:51
  • @arjuncc how can I do that ? I don't really understand what you're saying. Commented Feb 14, 2013 at 8:53

2 Answers 2

1
  $(document).ready(function(){
  $('table').hover(function(){
    $( ".changeClass" ).each(function() {
    if($(this).val()=='No')
    {
    $(this).addClass( "second" );
    $(this).parent().parent().find('.submitClass').prop('disabled', true);
    }
    else
    {
    $(this).addClass( "first" );
    }
    });
    return true;
    })
});



  <input type="text" class="changeClass"  name="status"  value="<?php echo$data['status']; ?>" >
Sign up to request clarification or add additional context in comments.

16 Comments

shorthand $j('.changeClass').removeClass('first').addClass('second');
Does this mean that the codes will add another class inside the class ?
@user1852728 sorry, i dont understand what do you meant to say
@user1852728: Not inside, you can have few class in the same element, like class="first second third", on the other hand, you can only have one id, #idname is the jquery selector based on id and '.classname' is for select an element based on the class name
I have a fiddle for you, This is what i understood from your requirement. If its not what you want. Then clear me. jsfiddle.net/QTp4X/1
|
0

Elements id in HTML must be unique. You should use the table id and go through the tables td children to do it. Or you can use the td class status and call them .status instead of #status in jquery.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.