Jump to content

Checkbox wont work


Help!php

Recommended Posts

I have a checkbox on a page and it works fine but if I copy the same thing to a different page with the exact same thing it wont work. Any idea why? I thought because of query but its using the same query to everything.

 

<?php $srchboxFormat = "A4"; $srchboxCategory = "Colour Laser";  $srchBoxHeading = "A4 Colour Laser Printer Finder"; require_once('includes/srchbox.php'); ?>

This is the file that shows the search box.

 

The code below shows the srchbox.php file

 

echo <<<_END


<div class='srchbox'>
<div class='srchboxbordertop'> </div>	

	<p class='srchboxheading'>{$srchBoxHeading}</p>

	<p class='srchboxhidden' id='format' name='format'>{$srchboxFormat}</p>
	<p class='srchboxhidden' id='category' name='category'>{$srchboxCategory}</p>
	<p class='srchboxhidden' id='pagenum' name='pagenum'>1</p>

	<div style='margin-left: 10px;' class='srchboxcolumn'>

			<p class='srchboxcoltitle'>Connectivity</p>

			<p class='srchboxfield'><input class='srchboxtick' onclick=fieldClick() value='' type='checkbox' id='usb' />USB</p>
			<p class='srchboxfield'><input class='srchboxtick' onclick=fieldClick() value='' type='checkbox' id='ethernet' />Network</p>
			<p class='srchboxfield'><input class='srchboxtick' onclick=fieldClick() value='' type='checkbox' id='wireless' />Wireless</p>
			<p class='srchboxfield'><input class='srchboxtick' onclick=fieldClick() value='' type='checkbox' id='parallel' />Parallel</p>

	</div>

	<div class='srchboxcolumn'>

			<p class='srchboxcoltitle'>Double-sided print</p>

			<p class='srchboxfield'><input class='srchboxtick' onclick=fieldClick() value='' type='checkbox' id='duplex' />Automatic</p>

	</div>

	<div class='srchboxcolumn'>

			<p class='srchboxcoltitle'>Compatibility</p>

			<p class='srchboxfield'><input class='srchboxtick' onclick=fieldClick() value='' type='checkbox' id='windows' />Windows</p>
			<p class='srchboxfield'><input class='srchboxtick' onclick=fieldClick() value='' type='checkbox' id='mac' />Mac</p>

			<p style='margin-top:38px' class='floatright'><img class='srchboxbtn' src='/images/reset.jpg' onclick='formReset()'/></p>

			<div class='clearfloats'></div>
	</div>

	<div class='srchboxcolumn'>

	<div class="floatleft" style="width: 100%; height: 100px; margin: 0px;">
				<p class='srchboxcoltitle'>Price range</p>

				<div class='floatleft'>Min price(£)</div>
				<div class="floatright">
					<select class="floatright" onchange=fieldClick() type='option' id='rrpmin' name='rrpmin'>						
						<option>0</option>
						<option>100</option>
						<option>200</option>
						<option>300</option>
						<option>400</option>
						<option>500</option>
						<option>600</option>
						<option>700</option>
						<option>800</option>
						<option>900</option>
						<option>1000</option>
						<option>1500</option>
						<option>2000</option>
						<option>3000</option>
						<option>4000</option>
						<option>5000</option>
						<option>10000</option>
					</select>
				</div>	

				<div class='clearfloats'></div>

				<p></p>

				<div class='floatleft'>Max price(£)</div>
				<div class="floatright">
					<select onchange=fieldClick() type='option' id='rrpmax' name='rrpmax' />
						<option>0</option>
						<option>100</option>
						<option>200</option>
						<option>300</option>
						<option>400</option>
						<option>500</option>
						<option>600</option>
						<option>700</option>
						<option>800</option>
						<option>900</option>
						<option>1000</option>
						<option>1500</option>
						<option>2000</option>
						<option>3000</option>
						<option>4000</option>
						<option>5000</option>
						<option>10000</option>
					</select>
				</div>

	</div>

		<div class='clearfloats'></div>
		<div id='srchboxmatch' class='srchboxmatch'>searching...</div>
		<p style="margin-top: 6px;" class='floatright'><img class='srchboxbtn' src='/images/show.jpg' onclick='formSubmit(0)' /></p>
	</div>

	<div class='srchboxborderbottom'> </div>	

</div>

<div class='clearfloats'></div>

<div style="width: 30%;" class="floatright">

	<div style="text-align: right; width: 40%;" class="floatleft">Sort by:</div>
	<div class="floatright">
		<select style="display: inline; width: 100px; font-size: 10px;" class="floatright" onchange=fieldClick() type='option' id='sortpref' name='sortpref'>						
			<option>Buyer rating</option>
			<option>Price (low to high)</option>
			<option>Price (high to low)</option>
		</select>
	</div>

</div>

<div class='clearfloats'></div>

_END;

 

After this.. there is another file which reads the selection and display the result.

 

can someone please help me

Link to comment
Share on other sites

There is no name set for them, and they also have no value set, I think the value is meant to be what you put in the id fields?

unless you are doing something with the javascript??, but name and value are the 2 things a form will use for post or get values

Link to comment
Share on other sites

Not using javascript. Yep it should be very simple. Use a form to post whats in the check post then use a $_POST or $_GET to the result. But its not. I cant seem to find any form. I am working on someone else code so not sure where is what.

 

This is the code that process the checkbox

 

	
function nametourl( $str )
{
	$str = str_replace(' ', '_', $str); 
	$str = trim($str);
	return $str;
}

if ( isset( $_GET[ 'srchboxqry' ] ) && isset( $_GET[ 'pagenum' ] ) )
{
	$rowsPerPage = 10;
	$pageNum = (int)$_GET[ 'pagenum' ]; 
	$rowNum = ( $pageNum - 1 ) * $rowsPerPage;

	$qry = $_GET[ 'srchboxqry' ];
	$qry = str_replace( "\\", "", $qry );

	//echo $qry; exit(0);
	mysql_select_db( $database_statusplc, $statusplc );
	$printerRS = mysql_query( $qry, $statusplc ) or die( mysql_error( ) );
	$numRows = mysql_num_rows( $printerRS );

	if ( $numRows == 0 )
	{
		echo "<p style='width: 100%; text-align: center; font-weight: bold; font-size: 18px; color: #990000;'>No printers found that match your criteria.</p>";
		exit(0);
	}

	if ( $rowNum > 0 )
		mysql_data_seek( $printerRS, $rowNum );

?>

			<?php 
			$record_count = 1;
			$row_printerRS = mysql_fetch_assoc($printerRS);

			do { 
			if($record_count % 2 == 1){$rowclass="printerlistshade";}
			else
			{$rowclass="printerlistnoshade";}
			?>
      
<div class="<?php echo $rowclass; ?>">

						<div class="div-full">
						<h2><a style="margin-left:0px;" class="homep-h2" class="listnav" href="printer/<?php echo $row_printerRS['productid']; ?>/<?php echo $row_printerRS[name] ;?>.php"><?php echo $row_printerRS['manufacturer']; ?> <?php echo $row_printerRS['name']; ?> 
						</a></h2>
						</div>

						<div class="printerlistname">

						<p style="margin-top:0px;"><?php echo $row_printerRS['promo']; ?></p>

						<strong><?php
						if($row_printerRS['format'] == null){

						echo  "N/A";

						}else

						{ echo $row_printerRS['format'];}

						?>
						<?php echo $row_printerRS['category']; ?> Printer</strong><br />

						<img src="/images/bull.gif" /> <?php

						$i = $row_printerRS['category'];

						switch ($i) {

						case "Mono Laser":

						echo $row_printerRS['bwppm'] . " ppm";

						break;

						case "Colour Laser":

						echo $row_printerRS['cppm'] . " ppm";

						break;

						case "Dot Matrix":

						echo $row_printerRS['bwppm'] . " cps";

						break;

						case "Inkjet":

						echo $row_printerRS['bwppm'] . " ppm";

						break;

						case "Line":

						echo $row_printerRS['bwppm'] . " lpm";

						break;

						case "Wide":

						echo $row_printerRS['cppm'] . " m<sup>2</sup> hour";

						break;

						case "Fax":

						echo $row_printerRS['Fmodem'] . " Kbs";

						break;

						case "Multifunction":

						echo $row_printerRS['bwppm'] . " ppm";

						break;

						default:

						}

						?>

						<br />

						<img src="/images/bull.gif" /> <?php echo $row_printerRS['resolution']; ?> dpi
		  

						<div class="special-stuff">*** <?php echo $row_printerRS['specialhead']; ?> ***</div>
		  
						</div>
             
						<div class="printerlistpic">

						<?php 
						$name = $row_printerRS['manufacturer'] . " " . $row_printerRS['name'];
						if($row_printerRS['image'] == ''){ ?>
						<a class="search" href="printer/<?php echo $row_printerRS['productid']; ?>/<?php echo nametourl($name) ;?>.php"><img onerror="ImgError(this);" src="images/products/<?php echo $row_printerRS['productid']; ?>.jpg" width="120"  border="0" alt="<?php echo $row_printerRS['name'];?>"></a>
						<?php }else{ ?>
						<a class="search" href="printer/<?php echo $row_printerRS['productid']; ?>/<?php echo nametourl($name) ;?>.php"><img onerror="ImgError(this);" src="images/products/<?php echo $row_printerRS['image']; ?>" width="120" border="0" alt="<?php echo $row_printerRS['name'];?>"></a>
						<?php } ?>

						<a href="printer/<?php echo $row_printerRS['productid']; ?>/<?php echo nametourl($name) ;?>.php"><img src="/images/more-info-sml.jpg" border="0" alt="More Information on this printer" /></a>

						</div>
            
						<div class="printerlistprice">

						JUST<br />

						<span class="lp-price"><?php echo "£" ;

						printf("%1.2f", $row_printerRS['rrp']); ?></span> <span class="sml-txt">(ex VAT)</span>		

						</div>

					</div>
			<?php 
			$record_count = $record_count + 1;
			} while ( ( $row_printerRS = mysql_fetch_assoc($printerRS) ) && ( $record_count <= $rowsPerPage ) ); ?>
<?php 				
echo <<<_END

	<div class='clearfloats'></div>
	<div class='srchboxbtns'>
_END;

		if ( $pageNum > 1 )
			echo "<div class='floatleft'><img style='cursor: pointer;' id='btnprev' onclick='btnPrev()' src='images/prev_orange.gif' border='0'></div>";

		if ( $numRows - ( $pageNum * $rowsPerPage ) > 0 )
			echo "<div class='floatright'><img style='cursor: pointer;' id='btnnext' onclick='btnNext()' src='images/next_orange.gif' border='0'></div>";

		echo "<div class='clearfloats'></div>";

		if ( $numRows <= $rowsPerPage )
			$pageTotal = 1;
		else
		{
			$pageTotal = floor( $numRows / $rowsPerPage );
			$pageTotal += ( $numRows % $rowsPerPage > 0 ) ? 1 : 0;
		}
		echo "<div class='srchboxpageinfo'>Page {$pageNum} of {$pageTotal}</div>";

echo <<<_END
	</div>

_END;

}

Link to comment
Share on other sites

these check boxes are using a javascript

 

<p class='srchboxfield'><input class='srchboxtick' onclick=fieldClick() value='' type='checkbox' id='usb' />USB</p>

 

see the onclick function set in there, that is a call to a javascript function called fieldClick(), I would guess you are missing this script

 

if you are not going to use this script then you need to set a name and a value for the check box, otherwise it wont be visible for processing and it wont contain the value data.

 

I also cant see any form tags either so I cant see if its using POST or GET, but I believe its using that fieldClick() to do the processing

Link to comment
Share on other sites

Someone already did this code for a company and I am just applying the same thing on another page using the same checkbox code page.. Its reading it from the same page so it should just work just like that.. unless the query is different.. but I checked that..

 

So the

<body onload="fieldClick('1')"> 

wasnt on the new page and I have done this bit now. But its still not working :/

Link to comment
Share on other sites

you need too look for the script, that is just another call to the same script, on the page usually in the head you will find the javascripts, they will be in <script> tags, one of them will have the function fieldClick() in it, that needs to be on your new page

 

Link to comment
Share on other sites

Awesome I found it :).. it works.. Thank you sooooooooooooooooooooooo much..

 

One more.. one of the check bos isnt working. I know this should be something really simple but I dont know where the issue is.

 

<p class='srchboxcoltitle'>Size</p>
			<p class='srchboxfield'><input class='srchboxtick' onclick=fieldClick() value='' type='checkbox' id='A3' />A3</p>
			<p class='srchboxfield'><input class='srchboxtick' onclick=fieldClick() value='' type='checkbox' id='A4' />A4</p>

 

A4 is working but A3 isnt showing any results

Link to comment
Share on other sites

There is not really enough information here for me to see what is happening, ie code as it is just bits, but you have the following line for A4 and A4 works

<?php $srchboxFormat = "A4"; $srchboxCategory = "Colour Laser";  $srchBoxHeading = "A4 Colour Laser Printer Finder"; require_once('includes/srchbox.php'); ?>

 

is there also one for A3?

and is it on the new page?

as you didnt post that in your code snippets so I really have no idea

 

Link to comment
Share on other sites

This is the line for a3.. but its the same php file.

 

<?php $srchboxFormat = "A3"; $srchboxCategory = "Colour Laser"; $srchBoxHeading = "A3 Colour Laser Printer Finder"; require_once('includes/srchbox.php'); ?>

 

whats inside srchbox.php is

 

echo <<<_END


<div class='srchbox'>
<div class='srchboxbordertop'> </div>	

	<p class='srchboxheading'>{$srchBoxHeading}</p>

	<p class='srchboxhidden' id='format' name='format'>{$srchboxFormat}</p>
	<p class='srchboxhidden' id='category' name='category'>{$srchboxCategory}</p>
	<p class='srchboxhidden' id='pagenum' name='pagenum'>1</p>

	<div style='margin-left: 10px;' class='srchboxcolumn'>

			<p class='srchboxcoltitle'>Connectivity</p>

			<p class='srchboxfield'><input class='srchboxtick' onclick=fieldClick() value='' type='checkbox' id='usb' />USB</p>
			<p class='srchboxfield'><input class='srchboxtick' onclick=fieldClick() value='' type='checkbox' id='ethernet' />Network</p>
			<p class='srchboxfield'><input class='srchboxtick' onclick=fieldClick() value='' type='checkbox' id='wireless' />Wireless</p>
			<p class='srchboxfield'><input class='srchboxtick' onclick=fieldClick() value='' type='checkbox' id='parallel' />Parallel</p>

	</div>

	<div class='srchboxcolumn'>

			<p class='srchboxcoltitle'>Double-sided print</p>

			<p class='srchboxfield'><input class='srchboxtick' onclick=fieldClick() value='' type='checkbox' id='duplex' />Automatic</p>

			<p class='srchboxcoltitle'>Size</p>
			<p class='srchboxfield'><input class='srchboxtick' onclick=fieldClick() value='' type='checkbox' id='A3' />A3</p>
			<p class='srchboxfield'><input class='srchboxtick' onclick=fieldClick() value='' type='checkbox' id='A4' />A4</p>

	</div>

	<div class='srchboxcolumn'>

			<p class='srchboxcoltitle'>Compatibility</p>

			<p class='srchboxfield'><input class='srchboxtick' onclick=fieldClick() value='' type='checkbox' id='windows' />Windows</p>
			<p class='srchboxfield'><input class='srchboxtick' onclick=fieldClick() value='' type='checkbox' id='mac' />Mac</p>

			<p style='margin-top:38px' class='floatright'><img class='srchboxbtn' src='/images/reset.jpg' onclick='formReset()'/></p>

			<div class='clearfloats'></div>
	</div>

	<div class='srchboxcolumn'>

	<div class="floatleft" style="width: 100%; height: 100px; margin: 0px;">
				<p class='srchboxcoltitle'>Price range</p>

				<div class='floatleft'>Min price(£)</div>
				<div class="floatright">
					<select class="floatright" onchange=fieldClick() type='option' id='rrpmin' name='rrpmin'>						
						<option>0</option>
						<option>100</option>
						<option>200</option>
						<option>300</option>
						<option>400</option>
						<option>500</option>
						<option>600</option>
						<option>700</option>
						<option>800</option>
						<option>900</option>
						<option>1000</option>
						<option>1500</option>
						<option>2000</option>
						<option>3000</option>
						<option>4000</option>
						<option>5000</option>
						<option>10000</option>
					</select>
				</div>	

				<div class='clearfloats'></div>

				<p></p>

				<div class='floatleft'>Max price(£)</div>
				<div class="floatright">
					<select onchange=fieldClick() type='option' id='rrpmax' name='rrpmax' />
						<option>0</option>
						<option>100</option>
						<option>200</option>
						<option>300</option>
						<option>400</option>
						<option>500</option>
						<option>600</option>
						<option>700</option>
						<option>800</option>
						<option>900</option>
						<option>1000</option>
						<option>1500</option>
						<option>2000</option>
						<option>3000</option>
						<option>4000</option>
						<option>5000</option>
						<option>10000</option>
					</select>
				</div>

	</div>

		<div class='clearfloats'></div>
		<div id='srchboxmatch' class='srchboxmatch'>searching...</div>
		<p style="margin-top: 6px;" class='floatright'><img class='srchboxbtn' src='/images/show.jpg' onclick='formSubmit(0)' /></p>
	</div>

	<div class='srchboxborderbottom'> </div>	

</div>

<div class='clearfloats'></div>

<div style="width: 30%;" class="floatright">

	<div style="text-align: right; width: 40%;" class="floatleft">Sort by:</div>
	<div class="floatright">
		<select style="display: inline; width: 100px; font-size: 10px;" class="floatright" onchange=fieldClick() type='option' id='sortpref' name='sortpref'>						
			<option>Buyer rating</option>
			<option>Price (low to high)</option>
			<option>Price (high to low)</option>
		</select>
	</div>

</div>

<div class='clearfloats'></div>

_END;

 

A3 and A4 srchbox code are same but these have different php page. I just want to combine them and have a search box for A3 and A4 under the checkbox. When they click on A4.. all the A4 should be displayed same goes for A3.

 

Thank you for helping me.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.