September 5, 201214 yr The title pretty much sums it up: I need the following form to be posted WITHOUT the page scrolling back to the top. I suppose I need some ajax/jquery, but I've never really worked with either, so I need some help! <form method="post" action="" class="kat" name="kat"> <select class="search2" name="kategori_id" id="kat"> <option selected>Anbefal til...</option> <option value="$cat[id]" id="$cat[id]">$cat[kategori] ($assigns)</option> // some PHP-code has been removed... </select> <input type="hidden" name="sang_id" value="<?php echo $id; ?>"> <input type="submit" class="button" name="kat" value="Anbefal" /> </form> <?php $ip=$_SERVER['REMOTE_ADDR']; if($_POST['kat']){ $kid = ($_POST['kategori_id']); $sid = ($_POST['sang_id']); $ip_sql=mysql_query("select ip_add from assign_kat where sang_id ='$sid' and ip_add='$ip'"); $count=mysql_num_rows($ip_sql); if($count==0) { $insert_news = mysql_query("INSERT INTO assign_kat (kat_id, sang_id, ip_add) VALUES ('$kid', '$sid', '$ip')")or die(mysql_error()); } if($count!=0) { $sql = "UPDATE assign_kat SET kat_id = '$kid' WHERE sang_id='$sid' and ip_add='$ip'"; mysql_query( $sql); } } ?>
September 5, 201214 yr Hi, you have 2 names of kat one on the input and one on the form, you can use jquery for this http://api.jquery.com/jQuery.post/
September 8, 201214 yr Author I've tried this, but it didn't work. What am I doing wrong!?! <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.7/jquery.js"></script> <script src="http://malsup.github.com/jquery.form.js"></script> <script> $('#kat').submit(function() { var queryString = $('#kat').formSerialize(); // submit the form $(this).ajaxSubmit(queryString); // return false to prevent normal browser submit and page navigation return false; }); </script>
Create an account or sign in to comment