views:

100

answers:

1

Hi how can i get all songs selected when i click playselected button without selecting any songs?

</style>
<script language=JavaScript>
function checkall()
{
void(d=document);
void(el=d.getElementsByName('song[]'));
for(i=0;i<el.length;i++)
void(el[i].checked=1)
}
function uncheckall()
{
void(d2=document);
void(e2=d2.getElementsByName('song[]'));
for(i=0;i<el.length;i++)
void(el[i].checked=0)
}

</script>

<form method="post" action="/player.php" target="player">
<table width="747" border="0" cellspacing="0" cellpadding="0">
  <tr>
    <td width="150" rowspan="6" valign="top">
    </td>
    <td height="120" colspan="3" align="center" valign="top"></td>
    <td width="176" rowspan="6" valign="top"></td>
  </tr>
  <tr>
    <!-- movie name -->
    <td width="179" height="150" align="center" valign="top"><h3><font color="#008080">moviename</font></h3>

      <!-- movie Description start (add description in between these tags)-->
<pre>


</pre>      <!-- movie Description end-->
      </td>
    <td colspan="2" valign="top"><img src="/images/moviename.jpg"></td>
    </tr>

  <tr>
    <td width="179" height="44" align="center"><input type=submit value="Play Selected"  /></td>
    <td width="86"><input type=button onClick="checkall()" value="Select All" name="button"></td>

    <td width="156"><input type=button onClick="uncheckall()" value="Invert Selection" name="button"></td>
  </tr>
  <tr>
    <td colspan="3" valign="top"><table height="342" cellspacing="0" cellpadding="0" border="0" width="423" class="VERDANAFONT">
      <tbody>
        <tr>
          <td width="423" height="38" align="left" valign="middle"><p> <font color="#339966">
<input type="checkbox" name="song[]" value="0_1 ,/telugusongs/moviename/0_1.mp3" />
            <!-- song names -->

            0_1 <br />
          </font></p></td>
          </tr>
        <tr>
          <td width="423" height="38" align="left" valign="middle"><p> <font color="#339966">
<input type="checkbox" name="song[]" value="0_2 ,/telugusongs/moviename/0_2.mp3" />
            <!-- song names -->
            0_2 <br />

          </font></p></td>
          </tr>
        <tr>
          <td width="423" height="38" align="left" valign="middle"><p> <font color="#339966">
<input type="checkbox" name="song[]" value="0_3 ,/telugusongs/moviename/0_3.mp3" />
            <!-- song names -->
            0_3 <br />
          </font></p></td>

          </tr>
        <tr>
          <td width="423" height="38" align="left" valign="middle"><p> <font color="#339966">
<input type="checkbox" name="song[]" value="0_4,/telugusongs/moviename/0_4.mp3" />
            <!-- song names -->
            0_4<br />
          </font></p></td>
          </tr>

        <tr>
          <td width="423" height="38" align="left" valign="middle"><p> <font color="#339966">
<input type="checkbox" name="song[]" value="0_5 ,/telugusongs/moviename/0_5.mp3" />
            <!-- song names -->
            0_5 <br />
          </font></p></td>
          </tr>
        <tr>

          <td width="423" height="38" align="left" valign="middle"><p> <font color="#339966">
<input type="checkbox" name="song[]" value="0_6 ,/telugusongs/moviename/0_6.mp3" />
            <!-- song names -->
            0_6<br />
          </font></p></td>
          </tr>
          <tr>
          <td width="423" height="38" align="left" valign="middle"><p> <font color="#339966">

<input type="checkbox" name="song[]" value="0_7 ,/telugusongs/moviename/0_7.mp3" />
            <!-- song names -->
            0_7 <br />
          </font></p></td>
          </tr>
          <tr>
          <td width="423" height="38" align="left" valign="middle"><p> <font color="#339966">
<input type="checkbox" name="song[]" value="0_8 ,/telugusongs/moviename/0_8.mp3" />
            <!-- song names -->

           0_8 <br />
          </font></p></td>
          </tr>
                </tbody>
    </table></td>
  </tr>
</table>
<table width="800" border="0" cellspacing="0" cellpadding="0">
  <tr>
  </tr>
</table>

am explaining clearly... when user select one song and if click on playselect button form will post one song. that is working perfect. but when user didnot select any song any if he clicked on playselected button ,in this situation i want all songs to be selected

A: 

adding an id to your playselect button, something like this should work

javascript only approach

<input type="Button" id="PlaySelected" value="Play Selected" 
onclick="checklist(myform)"/>//minor changes here made

function checklist(field)
{
   var answer=false;
   for (i = 0; i < field.length; i++)
   {
     if (field[i].type=="checkbox" && field[i].checked){
        answer=true;
        return false;
     }
   }
   for (i = 0; i < field.length; i++)
   {
       field[i].checked = true ;
   }
}

Also I forgot to mention to you to add the name "myform" to your form tag: Here is a

Click here for Demo working version

jQuery

$('#PlaySelected').click(function()
{
  var answer=false;
  $('input[type='checkbox']').each(function(){
    answer = this.checked;
    if(answer==true)
    {
      return false;
    }
  });
  $('input[type='checkbox']').each(function(){
        $(this).attr('checked', true);
  });
});
TStamper
sorry to ask....can u please tell me where i have to add code from $in my code
musicking123
? im not sure what you're asking you're asking where to add the jquery code?
TStamper
refer to http://docs.jquery.com/Tutorials:Getting_Started_with_jQuery for more detail and examples
TStamper
Im sorry, i assumed you wanted the answer in jquery, would you rather want it in javascript?
TStamper
ha...java script is better.......can u please provide it in java script...please
musicking123
@musicking- actually jquery is javascript, but its a more slicker and easier way of doing things
TStamper
thank you for ur help...........bracket after song[] is a vector which will contain the address of each song selected to play.
musicking123
but this code not working..............i added javascript which u send.
musicking123
update your first **<script>** tag to **<script type="text/javascript">**
TStamper