kvnirvana Posted October 22, 2010 Share Posted October 22, 2010 Based on what is chosen from the drop down it generates 3 star ratings underneath. But when the first star rating is clicked all the star ratings disappears, and the drop down list goes to the top where it says “Choose” it is like the drop down list is reloaded How can I do it so that when the star rating is clicked the drop down list doesn’t reload and remove the star rating? Think it must have something to do with the ajax? This is the page called "start" with the dropdowns <?php require('_drawrating.php'); ?> <?php require('_drawrating1.php'); ?> <?php require('_drawrating2.php'); ?> <?php require('_drawratingoverall.php'); ?> <script type="text/javascript" language="javascript" src="js/behavior.js"></script> <script type="text/javascript" language="javascript" src="js/rating.js"></script> <link rel="stylesheet" type="text/css" href="css/default.css" /> <link rel="stylesheet" type="text/css" href="css/rating.css" /> <script type="text/javascript"> function showUser(str) { if (str=="") { document.getElementById("txtHint").innerHTML=""; return; } if (window.XMLHttpRequest) {// code for IE7+, Firefox, Chrome, Opera, Safari xmlhttp=new XMLHttpRequest(); } else {// code for IE6, IE5 xmlhttp=new ActiveXObject("Microsoft.XMLHTTP"); } xmlhttp.onreadystatechange=function() { if (xmlhttp.readyState==4 && xmlhttp.status==200) { document.getElementById("txtHint").innerHTML=xmlhttp.responseText; } } xmlhttp.open("GET","des.php?q="+str+"&n=<?php echo $_GET['n']; ?>"+"&pr=<?php echo $_GET['pr']; ?>"+"&id=<?php echo $_GET['id']; ?>"+"&be=<?php echo $_GET['be']; ?>"+"&om=<?php echo $_GET['om']; ?>"+"&ad=<?php echo $_GET['ad']; ?>"+"&tf=<?php echo $_GET['tf']; ?>"+"&pos=<?php echo $_GET['pos']; ?>",true); xmlhttp.send(""); } </script> <?php if (isset($_POST['submit'])) { search(); //call the search function }else{ //end if /*------------------------------------------------------------------------ show the search form ------------------------------------------------------------------------*/ //call the dropdown function which creates an html string to build a select box for each element $p = dropdown('p','be'); $n = dropdown('n','be'); $om = dropdown('om','be'); $id=$_GET["id"]; echo " <table width='800' > <div style='position:relative;left:400px;top:20px;z-index:1> <tr> <td colspan='2' style='font-family:verdana;font-size:130%'> <p ><strong> Bedøm {$_GET['be']}, {$_GET['n']} </strong></p> </td></tr> <br><br> </div><div> <tr> <td style='font-family:verdana;font-size:130%'><p>Who {$_GET['be']}, {$_GET['n']}?</p></td> </tr> </div></table> <form method=post> <select name='select1' onchange='showUser(this.value)'> <option value=''>Choose</option> <option value='rg'>Rg</option> <option value='am'>Am</option> <option value='f'>F</option> </select> <div id='txtHint' ></div> </form>"; if(isset($_POST['select1'])) { // Fetch and clean the <select> value. // The (int) makes sure the value is really a integer. $qty = (int)$_POST['select1']; // Create the INSERT query. $sql = "INSERT INTO `be`(`pr`) VALUES ({$qty})"; // Connect to a database and execute the query. $dbLink = mysql_connect('', '', '') or die(mysql_error()); mysql_select_db('', $dbLink) or die(mysql_errno()); $result = mysql_query($sql); // Check the results and print the appropriate message. if($result) { echo "Record successfully inserted!"; } else { echo "Record not inserted! (". mysql_error() .")"; } } } function dropdown($field, $table) { //initialize variables $oHTML = ''; $result = ''; //check to see if the field is passed correctly if (($field == "")||($table == "")) { die("No column or table specified to create drop down from!"); } $sql = "select distinct($field) from $table"; //call the db function and run the query $result = conn($sql); //if no results are found to create a drop down return a textbox if ((!$result) ||(mysql_num_rows($result)==0)) { $oHTML .= "<input type='text' name='$field' value='' size='15'>"; }elseif (($result)&&(mysql_num_rows($result)>0)){ //build the select box out of the results while ($rows = mysql_fetch_array($result)) { $oHTML .= "<option value='".$rows[$field]."'>".$rows[$field]."</option>\n"; } $oHTML .= "</select>\n"; } //send the value back to the calling code return $oHTML; }//end function echo "<table>"; echo "<div>"; echo "<tr></td> <td style='position:absolute;right:18px;top:36px' 'tdimage' BACKGROUND='forside1.jpg' width='290' height='600'></td></tr>"; echo "</div>"; echo "</table>"; /*------------------------------------------------------------------------ ?> This is the page called des.php with the rating stars <?php require('_drawrating.php'); ?> <?php require('_drawrating1.php'); ?> <?php require('_drawrating2.php'); ?> <?php require('_drawratingoverall.php'); ?> <?php require('_drawratingforsjov.php'); ?> <script type="text/javascript" language="javascript" src="js/behavior.js"></script> <script type="text/javascript" language="javascript" src="js/rating.js"></script> <link rel="stylesheet" type="text/css" href="css/default.css" /> <link rel="stylesheet" type="text/css" href="css/rating.css" /> <?php $con = mysql_connect("","",""); mysql_select_db("", $con); $sqll = mysql_query("select * from beh WHERE n='" . $_GET['n'] . "'and pr='" . $_GET['q'] . "'") or die ("query 1: " . mysql_error()); $mysql_num = mysql_num_rows($sqll); if ($mysql_num >= 1) { echo ''; } else { ##Run insert query. $con = mysql_connect("","",""); if (!$con) { die('Could not connect: ' . mysql_error()); } mysql_select_db("", $con); $am = mysql_real_escape_string($_GET['q']); $n = mysql_real_escape_string($_GET['n']); $be = mysql_real_escape_string($_GET['be']); $om = mysql_real_escape_string($_GET['om']); $ad = mysql_real_escape_string($_GET['ad']); $tf = mysql_real_escape_string($_GET['tf']); $pos = mysql_real_escape_string($_GET['pos']); $sql="INSERT INTO beh (pr, n, be, om, ad, tf, pos) VALUES ('{$ar}', '{$n}', '{$be}', '{$om}', '{$ad}', '{$tf}', '{$pos}')"; if (!mysql_query($sql,$con)) { die('Error: ' . mysql_error()); }} echo ""; mysql_close($con) ?> <?php header("Content-Type: text/plain; charset=ISO-8859-1"); header("Cache-Control: no-cache, must-revalidate"); header("Expires: Sat, 26 Jul 1997 05:00:00 GMT"); $sql = "select * from beh WHERE n='" . $_GET['n'] . "'and pr='" . $_GET['q'] . "'" or die(mysql_error()); //run query $result = conn($sql); if (!$result){ die("No results due to database error.<br>".mysql_error()); } if (mysql_num_rows($result)==0) { echo "No Results found!"; }else{ $words = array('r', 'am'); // Replace or add all the words that you want $q = $_GET['q']; while ($rows= mysql_fetch_array($result)) { echo " <table width='70%' > <TR><br><br><p style='font-family:verdana;font-size:130%;'>How many stars {$_GET['be']}, {$_GET['n']} "; if (in_array($q, $words)) { echo " di $q?</p>"; } else { echo " dt $q?</p>"; } "</TR></table>"; }{ echo " <table width='70%' > <TR><br><br> <p style='font-family:verdana;font-size:130%;'> </p>"; ?> <?php echo rating_bar($rows['id'],'6'); ?> <?php echo "</TR></table>"; }{ echo " <table width='70%' > <TR><br><br> <p style='font-family:verdana;font-size:130%;'> </p>"; ?> <?php echo rating_bar1($rows['id'],'6'); ?> <?php echo "</TR></table>"; }{ echo " <table width='70%' > <TR><br><br> <p style='font-family:verdana;font-size:130%;'> </p>"; ?> <?php echo rating_bar2($rows['id'],'6'); ?> <?php echo "</TR></table>"; } } </body> </html> Quote Link to comment https://forums.phpfreaks.com/topic/216583-star-rating-disappears/ 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.