Help!php Posted March 14, 2012 Share Posted March 14, 2012 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 Quote Link to comment https://forums.phpfreaks.com/topic/258921-checkbox-wont-work/ Share on other sites More sharing options...
dragon_sa Posted March 14, 2012 Share Posted March 14, 2012 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 Quote Link to comment https://forums.phpfreaks.com/topic/258921-checkbox-wont-work/#findComment-1327402 Share on other sites More sharing options...
Help!php Posted March 15, 2012 Author Share Posted March 15, 2012 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; } Quote Link to comment https://forums.phpfreaks.com/topic/258921-checkbox-wont-work/#findComment-1327588 Share on other sites More sharing options...
dragon_sa Posted March 15, 2012 Share Posted March 15, 2012 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 Quote Link to comment https://forums.phpfreaks.com/topic/258921-checkbox-wont-work/#findComment-1327592 Share on other sites More sharing options...
Help!php Posted March 15, 2012 Author Share Posted March 15, 2012 Oh no! I dont know javascript at all. Since I am going through someone else code to modify I am screwed. Anyway you can help me with understanding this code??? Quote Link to comment https://forums.phpfreaks.com/topic/258921-checkbox-wont-work/#findComment-1327594 Share on other sites More sharing options...
dragon_sa Posted March 15, 2012 Share Posted March 15, 2012 You said you copied this code from another page, I would look at the other page and look for a javascript function called fieldClick() and make sure that it is on the new page you are trying to make this work on. Quote Link to comment https://forums.phpfreaks.com/topic/258921-checkbox-wont-work/#findComment-1327609 Share on other sites More sharing options...
Help!php Posted March 15, 2012 Author Share Posted March 15, 2012 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 :/ Quote Link to comment https://forums.phpfreaks.com/topic/258921-checkbox-wont-work/#findComment-1327615 Share on other sites More sharing options...
dragon_sa Posted March 15, 2012 Share Posted March 15, 2012 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 Quote Link to comment https://forums.phpfreaks.com/topic/258921-checkbox-wont-work/#findComment-1327618 Share on other sites More sharing options...
Help!php Posted March 15, 2012 Author Share Posted March 15, 2012 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 Quote Link to comment https://forums.phpfreaks.com/topic/258921-checkbox-wont-work/#findComment-1327623 Share on other sites More sharing options...
dragon_sa Posted March 15, 2012 Share Posted March 15, 2012 are you sure there should be results for A3? Maybe the returned result is empty Quote Link to comment https://forums.phpfreaks.com/topic/258921-checkbox-wont-work/#findComment-1327626 Share on other sites More sharing options...
Help!php Posted March 15, 2012 Author Share Posted March 15, 2012 There should be result. A3 or A4.. you select one of these and it should print the A3 ones if A3 is selected. If its A4 then A4 will be printer. A4 works but A3 doesnt.. Yh I think so. How do I fix the return result.. Quote Link to comment https://forums.phpfreaks.com/topic/258921-checkbox-wont-work/#findComment-1327628 Share on other sites More sharing options...
dragon_sa Posted March 15, 2012 Share Posted March 15, 2012 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 Quote Link to comment https://forums.phpfreaks.com/topic/258921-checkbox-wont-work/#findComment-1327635 Share on other sites More sharing options...
Help!php Posted March 15, 2012 Author Share Posted March 15, 2012 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. Quote Link to comment https://forums.phpfreaks.com/topic/258921-checkbox-wont-work/#findComment-1327652 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.