Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

my submit button stoped working after chaigng id to id[]

Status
Not open for further replies.

keith23

Technical User
Joined
May 26, 2005
Messages
97
Location
NL
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;
                            [B]<button id="playSelected" onclick="playme()">Play Selected</button>&nbsp;&nbsp;[/B]                            <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>
 
According to W3C standards, form element names and ids should not have the square brackets in the values. Since the square bracket is a reserved character in Javascript, you're asking for trouble if you make this a practice. Your other button WILL work without the square brackets, but you'll have to write the code for it to function properly. This is a common problem that new PHP scripters cause themselves.

Lee
 
trollacious maony thanks for u reply. could u tell me how i can make my other submit work without chaning checkbox name from id to id[]? Here is my code for the reciving value of check box :
[/code]
<?php

//echo $_POST['id'];

$user = "root";
$pw = "";
$db = "test2";
$mysql_access = mysql_connect("localhost", $user, $pw);
mysql_select_db($db, $mysql_access);

$fragments = $_POST['Id'];

$loopCount = count($fragments);

for ($loop = 0; $loop < $loopCount; $loop++) {
if ($where != '') $where .= ' OR';
$where .= ' id='.$fragments[$loop].' ';
}

$query = "select * from files where $where";

....

Code:
 
You need to show the final HTML output, not the PHP.

Lee
 
Thank u for u reply. This is html code that get generated once 3 songs are checked and submit button clicked:
I still have one problem with it that id value is empty k!!
my query selects all feilds but it does not put value of id i do not know why!

Code:
<div align="center">
  <center>
  <table border="0" cellpadding="0" cellspacing="0" style="border-collapse: collapse" bordercolor="#111111" width="70%" id="AutoNumber1">

	<form action="/Members/Add.php" method=post >
	<input name="go" type="hidden" value="yes">
    <tr>
      <td width="20%" height="23">Add to Playlist:
      </td>
  
    </tr>
    
    <tr>
      <td colspan=2 height="1">
      		<table border="1">
 				 <tr>
    				<td width="3%">&nbsp;</td>
   					<td width="50%"><b>Song Name</b></td>
    				<td width="20%"><b>Album</b></td>
    				<td width="10%"><b>Language</b></td>
    				<td width="5%"><b>Hits</b></td>
  				</tr>

 <tr>
    				<td width="3%"><input type="checkbox" name="id" value="" checked></td>
   					<td width="50%">song1</b>&nbsp;</td>
    				<td width="20%">album1&nbsp;</td>
    				<td width="10%">D&nbsp;</td>
    				<td width="5%">33&nbsp;</td>
  				</tr>

 <tr>
    				<td width="3%"><input type="checkbox" name="id" value="" checked></td>
   					<td width="50%">song2</b>&nbsp;</td>
    				<td width="20%">album2&nbsp;</td>
    				<td width="10%">D&nbsp;</td>
    				<td width="5%">33&nbsp;</td>
  				</tr>

 <tr>
    				<td width="3%"><input type="checkbox" name="id" value="" checked></td>
   					<td width="50%">song3</b>&nbsp;</td>
    				<td width="20%">album3&nbsp;</td>
    				<td width="10%">D&nbsp;</td>
    				<td width="5%">33&nbsp;</td>
  				</tr>




	  
      		</table>
      </td>
    </tr>
    
    
    <tr>
      <td colspan=2 height="27">
      <p align="center">
      <input type="submit" value="Add this/these Songs to my PlayList" name="B1">
      </td>
    </tr>
    </form>
  </table>
  </center>
</div>
</body>
 
The problem appears to be a PHP one, not Javascript, since the values are supposed to be written by PHP into the HTML for the checkboxes. You'll want to post that, with the PHP code that writes the checkboxes, in the PHP forum.

forum434

Lee
 
... Where the good folks will no doubt send you straight back here, telling you to add "[]" to your ID.

If they do - please, point out that "[]" is not valid, and that you require another way of accessing those elements.

Dan



[tt]Dan's Page [blue]@[/blue] Code Couch
[/tt]
 
well that is what they suggested to my from php fourm and i hate that []since after using that half of my application stoped working. I have seen sites that they do the same thing using asp without [] but i do not know how!!
 
It's a problem with PHP. Trying to force web developers to suddenly use "[" and "]" characters in their front-end coding, when the HTML specs have been around for a lot longer that PHP is really bad.

You really should simply avoid using "[" and "]" and find another way (in the PHP forum) to deal with this. Someone must know a way... after all, I'm sure there must be many PHP pages out there that validate, but have control arrays on them.

Dan



[tt]Dan's Page [blue]@[/blue] Code Couch
[/tt]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top