Results 1 to 8 of 8
  1. #1
    Join Date
    Apr 2005
    Posts
    203

    Arrow Unanswered: my submit button stoped working after chaigng id to id[]

    Hi all i have problem with my java script that stoped working after chaning check box name from id to id[].

    In one page i have 3 buttons. one that uses javascript to send songs to another page via url get method. One that submits check box values to next page via post .The 3th one clears the checkboxes.The problem is after changing the checkbox name Id to Id[] my other button that uses java script stoped working . . i need to keep the check box name as id[] since my other button will not work without [].I encluded the code bellow.I be happy if i get help fixing this poblem so that both buttons works.Thanks

    java script code;

    Code:
    <script language="javascript">
    <!-- hide
    var checkflag = "false";
    function check(field) {
    if (checkflag == "false") {
    for (i = 0; i < field.length; i++) {
    field[i].checked = true;}
    checkflag = "true";
    return "Uncheck All"; }
    else {
    for (i = 0; i < field.length; i++) {
    field[i].checked = false; }
    checkflag = "false";
    return "Check All"; }
    }
    
    function newWindow(url) { 
     var x,y;
     x = screen.width-35;
     y = screen.height-30;
     var win = window.open(url,'glossaryWindow','toolbar=no,directories=no,width=500,height=150'+
     'screenX=0,screenY=0,top=0,left=0,location=no,status=no,scrollbars=no,resize=yes,menubar=no');
    }  
    
    // Start of Playme Function
    function playme()
    {
    Id = document.forms.mp3Play.Id;
    tempUrl ='';
    url = '';
    
    if (Id.length > 0){  
     for (i=0; i<Id.length; ++ i)
     {
      if (Id[i].checked)
     {
      tempUrl =tempUrl +"|" + Id[i].value
      if (i == 30)
      {
       alert("Each time you can only select 30 songs to play")
       return false;
      }
     }
     }
    }
    else
     {
      alert("it is less than 0#2")
      tempUrl = tempUrl + "&Id=" + Id.value
     }
     //alert(tempUrl);
     url = "./mp3s/myWimpy.php?queryWhere=Id&queryValue=" + tempUrl;
     newWindow(url);
     return false;
    }  
    // End of Playme Function 
    // --> 
    </script>

    checkbox page cuttons:


    Code:
      <tr>
              <td colspan=7>
                                <p align="center">
                                <input type=button value="Check All" onClick="this.value=check(this.form.Id)"> &nbsp;&nbsp;
                                <button id="playSelected" onclick="playme()">Play Selected</button>&nbsp;&nbsp;                            <input type="submit" value="Add to PlayList [Members]" name="B1">&nbsp;&nbsp;
                                </td>
            </tr>
    checkbox code :

    Code:
    <input
                            type="checkbox" name="Id[]" value='<?=intval( $row['id'] );?>' /></td>

  2. #2
    Join Date
    Apr 2005
    Location
    Baltimore, MD
    Posts
    297
    Could you be more specific as to what works and what doesn't? Also, how the "broken" features are supposed to work? What did you change that made the script not work? Was it just the name fields?

    And could you post at least your whole form? Can't really get much by looking at bits and pieces.

  3. #3
    Join Date
    Apr 2005
    Posts
    203

    Arrow

    Quote Originally Posted by jfulton
    Could you be more specific as to what works and what doesn't? Also, how the "broken" features are supposed to work? What did you change that made the script not work? Was it just the name fields?

    And could you post at least your whole form? Can't really get much by looking at bits and pieces.
    Well i changed my checkbox name from id to id[] so that my form post method work. Now my form post method works and passes values but my others submit button that activates my java script stoped working . When click on it nothing happens. I want both my buttons work !

  4. #4
    Join Date
    Apr 2005
    Location
    Baltimore, MD
    Posts
    297
    Want to try posting your whole form and any other relevant code??? If you are incorrectly using names/ids in your form, then your problem may not be in your javascript. Or if not, then you're probably just trying to get the elements incorrectly.

    Nobody's going to be able to help if you just tell us that some button "stopped working" without giving us something to look at.

    Are you sure when you click your button nothing happens? You probably just need to rewrite your "checkall" function. Especially if you are accessing your form elements by name.

  5. #5
    Join Date
    Apr 2005
    Posts
    203
    Quote Originally Posted by jfulton
    Want to try posting your whole form and any other relevant code??? If you are incorrectly using names/ids in your form, then your problem may not be in your javascript. Or if not, then you're probably just trying to get the elements incorrectly.

    Nobody's going to be able to help if you just tell us that some button "stopped working" without giving us something to look at.

    Are you sure when you click your button nothing happens? You probably just need to rewrite your "checkall" function. Especially if you are accessing your form elements by name.

    Here is the complet code. the button codes are shown in bold.Thanks
    Code:
    <html>
    <head>
    <link rel="stylesheet" type="text/css" href="../include/default.css">
    <meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
    <title> </title>
    </head>
    <body topmargin="0" leftmargin="0" ONLOAD="preloadImages();">
    
    <div align="center">
      <center>
      <tablewidth="100%" id="AutoNumber1">
        <tr>
          <td width="100%">
          <table width="100%" cellspacing="0" cellpadding="0" border="0">
          	<tr>
          		<td>
          		 <!-- ImageReady Preload Script (toplogo.psd) -->
    <script language="javascript">
    <!-- hide
    var checkflag = "false";
    function check(field) {
    if (checkflag == "false") {
    for (i = 0; i < field.length; i++) {
    field[i].checked = true;}
    checkflag = "true";
    return "Uncheck All"; }
    else {
    for (i = 0; i < field.length; i++) {
    field[i].checked = false; }
    checkflag = "false";
    return "Check All"; }
    }
    
    function newWindow(url) { 
    	var x,y;
    	x = screen.width-35;
    	y = screen.height-30;
    	var win = window.open(url,'glossaryWindow','toolbar=no,directories=no,width=500,height=150'+
    	'screenX=0,screenY=0,top=0,left=0,location=no,status=no,scrollbars=no,resize=yes,menubar=no');
    }  
    
    // Start of Playme Function
    function playme()
    {
    
    ID = document.forms.mp3Play.Id[]
    tempUrl ='';
    url = '';
    
    if (Id.length > 0){  
     for (i=0; i<Id.length; ++ i)
     {
    	 if (Id[i].checked)
    	{
    		tempUrl =tempUrl +"|" + Id[i].value
    		if (i == 30)
    		{
    			alert("Each time you can only select 30 songs to play")
    			return false;
    		}
    	}
     }
    }
    else
    	{
    		alert("it is less than 0#2")
    		tempUrl = tempUrl + "&Id=" + Id.value
    	}
    	//alert(tempUrl);
    	url = "./mp3s/myWimpy.php?queryWhere=Id&queryValue=" + tempUrl;
    	newWindow(url);
    	return false;
    }		
    // End of Playme Function	
    // -->	
    </script>
       			<div align="center">
      			<center>
        
                	<table border="0" width="95%" id="table1" bordercolorlight="#008ED2" cellspacing="1" style="border-style:dashed; "#008ED2" colspan=7 style="border-style: dashed" cellpadding="0">
    			 		<tr>
        	
     						<form method="POST" action="./Members/AddToPlayList.php"  name="mp3Play">
     						 <tr>
        						<td colspan=7 bgcolor="#323E8D">
                                <p align="center"><font color="#FFFFFF">
    							::: Singer: <b></b> Album <b></b>::::</font></td>
      						</tr>
     						 <tr>
     						 	<td width="3%">
    							<p align="center"><b>#</b></td>
        						<td width="3%">&nbsp;</td>
       							<td width="20%"><b>Song Name </b></td>
        						<td width="15%"><b>Album</b></td>
        						<td width="10%"><b>Rate It</b></td>
        						<td width="5%"><b>Hits</b></td>
        						<td width="20%"><b>Lyrics</b></td>
      						</tr>
    			
    					
    <tr>
                            <td bgcolor="#C0C0C0"><p align="center"><b>1</b></p>
                            </td>
                            <td bgcolor="#C0C0C0"><input
                            type="checkbox" name="Id[]" value='389' /></td>
    
                            <td bgcolor="#C0C0C0"><a
                            href="javascript:newWindow('./mp3s/myWimpy.php?queryWhere=Id&queryValue=389')"><img
                            src="images/Speaker.gif"
                            alt="Listen to this Song" border="0"
                            width="16" height="16"
                            longdesc="Listen to this Song"></a>&nbsp;Ze Kohyat Bar Griftam                         </td>
                            <td bgcolor="#C0C0C0">Morghe Dil</td>
                            <td bgcolor="#C0C0C0"><a
                            href="javascript:newWindow('RateSong.asp?SongID=1')"><img
                            src="images/RatIt.gif"
                            alt="Rate This Song" border="0"
                            width="100" height="22"
                            longdesc="Rate This Song"></a></td>
                            <td align="center" bgcolor="#C0C0C0">0&nbsp;</td>
                            <td bgcolor="#C0C0C0">coming Soon <!-- <a href="../site.php?songID=1&Song=Atash">Read </a>| <a href="./Members/WriteLyrics.php?SongId=1&Song=Atash">Write</a> --> </td>
    
    <tr>
                            <td bgcolor="#C0C0C0"><p align="center"><b>2</b></p>
                            </td>
                            <td bgcolor="#C0C0C0">
    
    <input
                            type="checkbox" name="Id[]" value='391' />  </td>
    
                            <td bgcolor="#C0C0C0"><a
                            href="javascript:newWindow('./mp3s/myWimpy.php?queryWhere=Id&queryValue=391')"><img
                            src="images/Speaker.gif"
                            alt="Listen to this Song" border="0"
                            width="16" height="16"
                            longdesc="Listen to this Song"></a>&nbsp;Khosho                      </td>
                            <td bgcolor="#C0C0C0">Morghe Dil</td>
                            <td bgcolor="#C0C0C0"><a
                            href="javascript:newWindow('RateSong.asp?SongID=1')"><img
                            src="images/RatIt.gif"
                            alt="Rate This Song" border="0"
                            width="100" height="22"
                            longdesc="Rate This Song"></a></td>
                            <td align="center" bgcolor="#C0C0C0">0&nbsp;</td>
                            <td bgcolor="#C0C0C0">coming Soon <!-- <a href="../site.php?songID=1&Song=Atash">Read </a>| <a href="./Members/WriteLyrics.php?SongId=1&Song=Atash">Write</a> --> </td>
    
    
                    
    
       		
    						<tr>
        						<td colspan=7>
                                <p align="center">
                                <input type=button value="Check All" onClick="this.value=check(this.form.Id)"> &nbsp;&nbsp;
                                <button id="playSelected" onclick="playme()">Play Selected</button>&nbsp;&nbsp;
                                <input type="submit" value="Add to PlayList [Members]" name="B1">&nbsp;&nbsp;
                                </td>
      						</tr>
      			
      		
      			
    			</table></center>
    			</div>
    
    
    
    
    
      
    </body>

  6. #6
    Join Date
    Apr 2005
    Location
    Baltimore, MD
    Posts
    297
    1. close your form tag

    2. onClick="this.value=check(this.form.Id)"
    this.form.Id is nothing. Try for yourself. Accessing elements this way is generally a very bad idea. Use children, siblings, or getElementById().

    Solution:
    Pass in the form to your function. Iterate through the form elements. For each checkbox, set its value.

    Code:
    checkAll(this.form);
    
    function checkAll(frm) {
         var fields = frm.elements;
         for (var i=0; i<fields.length; i++) {
               //if fields[i] is checkbox, check/uncheck
         }
    }

  7. #7
    Join Date
    Apr 2005
    Posts
    203
    Quote Originally Posted by jfulton
    1. close your form tag

    2. onClick="this.value=check(this.form.Id)"
    this.form.Id is nothing. Try for yourself. Accessing elements this way is generally a very bad idea. Use children, siblings, or getElementById().

    Solution:
    Pass in the form to your function. Iterate through the form elements. For each checkbox, set its value.

    Code:
    checkAll(this.form);
    
    function checkAll(frm) {
         var fields = frm.elements;
         for (var i=0; i<fields.length; i++) {
               //if fields[i] is checkbox, check/uncheck
         }
    }
    The problem is that i do not know much javascript and the code i downloaded it from a site!! :-(

  8. #8
    Join Date
    Apr 2005
    Location
    Baltimore, MD
    Posts
    297
    It's never too late to learn!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •