hahaitwork Posted November 1, 2012 Share Posted November 1, 2012 When I press any buttons to delete, add or subtracts (etc) things on my website, it always go to the top, like if it's refreshing the site. Any idea how I can avoid this ? Is it possible overall? Quote Link to comment https://forums.phpfreaks.com/topic/270151-website-scrolls-up-when-buttons-are-pressed/ Share on other sites More sharing options...
Beeeeney Posted November 1, 2012 Share Posted November 1, 2012 When I press any buttons to delete, add or subtracts (etc) things on my website, it always go to the top, like if it's refreshing the site. Any idea how I can avoid this ? Is it possible overall? Give us a bit more information than that, internet stranger. Is your website live? Can we have a link? Quote Link to comment https://forums.phpfreaks.com/topic/270151-website-scrolls-up-when-buttons-are-pressed/#findComment-1389236 Share on other sites More sharing options...
hahaitwork Posted November 1, 2012 Author Share Posted November 1, 2012 no my website is not live, but it's like.. pressing a button, and the coding i have is almost like ajax etc.. so, it refresh it self because it needs to update the php stuff within the file, BUT I need it to stay and not jump to the top ;\ Quote Link to comment https://forums.phpfreaks.com/topic/270151-website-scrolls-up-when-buttons-are-pressed/#findComment-1389238 Share on other sites More sharing options...
Beeeeney Posted November 1, 2012 Share Posted November 1, 2012 Almost like Ajax? If you want only part of your page to update, then you need to be using Ajax. Quote Link to comment https://forums.phpfreaks.com/topic/270151-website-scrolls-up-when-buttons-are-pressed/#findComment-1389240 Share on other sites More sharing options...
hahaitwork Posted November 1, 2012 Author Share Posted November 1, 2012 Almost like Ajax? If you want only part of your page to update, then you need to be using Ajax. It is Ajax.. just wasn't sure if that was the correct name for it Quote Link to comment https://forums.phpfreaks.com/topic/270151-website-scrolls-up-when-buttons-are-pressed/#findComment-1389243 Share on other sites More sharing options...
Beeeeney Posted November 1, 2012 Share Posted November 1, 2012 It is Ajax.. just wasn't sure if that was the correct name for it Well then clearly there is something wrong with the way you've built it, but you haven't posted any code. Quote Link to comment https://forums.phpfreaks.com/topic/270151-website-scrolls-up-when-buttons-are-pressed/#findComment-1389256 Share on other sites More sharing options...
hahaitwork Posted November 1, 2012 Author Share Posted November 1, 2012 Well then clearly there is something wrong with the way you've built it, but you haven't posted any code. Well, here is some of the code that can be the reason? if (isset ($_GET['add'])) { $quantity = mysql_query ('SELECT id, quantity FROM products WHERE id=' .mysql_real_escape_string ((int) $_GET ['add'])); while ($quantity_row = mysql_fetch_assoc ($quantity)) { if ($quantity_row['quantity'] !=$_SESSION['cart_'.(int)$_GET['add']]) { $_SESSION['cart_'.(int)$_GET['add']]+='1'; } } header('Location: '.$page); } if (isset($_GET['remove'])) { $_SESSION['cart_'.(int)$_GET['remove']]--; header('Location: '.$page); } if (isset($_GET['delete'])) { $_SESSION['cart_'.(int)$_GET['delete']]='0'; header('Location: '.$page); } Quote Link to comment https://forums.phpfreaks.com/topic/270151-website-scrolls-up-when-buttons-are-pressed/#findComment-1389284 Share on other sites More sharing options...
ManiacDan Posted November 1, 2012 Share Posted November 1, 2012 The <a> tag itself probably has an href="#". That will scroll to the top of the page unless the onclick of that <a> tag has return false at the end. Quote Link to comment https://forums.phpfreaks.com/topic/270151-website-scrolls-up-when-buttons-are-pressed/#findComment-1389291 Share on other sites More sharing options...
hahaitwork Posted November 1, 2012 Author Share Posted November 1, 2012 The <a> tag itself probably has an href="#". That will scroll to the top of the page unless the onclick of that <a> tag has return false at the end. When I press a "delete, add or subtract" button, this scripts will be runned, but they do not have a "#". They do have for eksample: <a href="cart.php?add=' .$get_row['id']. '"> Quote Link to comment https://forums.phpfreaks.com/topic/270151-website-scrolls-up-when-buttons-are-pressed/#findComment-1389301 Share on other sites More sharing options...
Jessica Posted November 1, 2012 Share Posted November 1, 2012 OP, are you being deliberately obtuse? Quote Link to comment https://forums.phpfreaks.com/topic/270151-website-scrolls-up-when-buttons-are-pressed/#findComment-1389303 Share on other sites More sharing options...
Beeeeney Posted November 1, 2012 Share Posted November 1, 2012 OP, are you being deliberately obtuse? I don't think so, considering the spelling of the word "Example". Quote Link to comment https://forums.phpfreaks.com/topic/270151-website-scrolls-up-when-buttons-are-pressed/#findComment-1389314 Share on other sites More sharing options...
ManiacDan Posted November 1, 2012 Share Posted November 1, 2012 You ARE refreshing the site. You're going to a whole new page. That's the problem: it's doing what you tell it to do. If you'd like to perform actions WITHOUT refreshing the page, use javascript. Quote Link to comment https://forums.phpfreaks.com/topic/270151-website-scrolls-up-when-buttons-are-pressed/#findComment-1389319 Share on other sites More sharing options...
hahaitwork Posted November 1, 2012 Author Share Posted November 1, 2012 You ARE refreshing the site. You're going to a whole new page. That's the problem: it's doing what you tell it to do. If you'd like to perform actions WITHOUT refreshing the page, use javascript. Well, with the code I have .. I think it will be pretty much I have to do different if I'm going to change to only using Javascript.. so, I hope that is not the only option? Quote Link to comment https://forums.phpfreaks.com/topic/270151-website-scrolls-up-when-buttons-are-pressed/#findComment-1389344 Share on other sites More sharing options...
hahaitwork Posted November 1, 2012 Author Share Posted November 1, 2012 I don't think so, considering the spelling of the word "Example". what's that suppose to mean? >_> I'm aware that my PHP/html (etc) skills are not far as good as you guys, but I'm here to find help.. i'm not here to be chopped at. Also.. I'm just telling you this, it's not because i'm angry. Quote Link to comment https://forums.phpfreaks.com/topic/270151-website-scrolls-up-when-buttons-are-pressed/#findComment-1389347 Share on other sites More sharing options...
Jessica Posted November 1, 2012 Share Posted November 1, 2012 If you don't want to refresh the page when you do something, you HAVE to use javascript. If that something requires working with PHP or MySQL, you HAVE to use AJAX. Quote Link to comment https://forums.phpfreaks.com/topic/270151-website-scrolls-up-when-buttons-are-pressed/#findComment-1389358 Share on other sites More sharing options...
Beeeeney Posted November 1, 2012 Share Posted November 1, 2012 (edited) what's that suppose to mean? >_> I'm aware that my PHP/html (etc) skills are not far as good as you guys, but I'm here to find help.. i'm not here to be chopped at. Also.. I'm just telling you this, it's not because i'm angry. I wasn't intentionally being a jerk, I'm sorry. Edited November 1, 2012 by ManiacDan language Quote Link to comment https://forums.phpfreaks.com/topic/270151-website-scrolls-up-when-buttons-are-pressed/#findComment-1389366 Share on other sites More sharing options...
hahaitwork Posted November 1, 2012 Author Share Posted November 1, 2012 I wasn't intentionally being a jerk, I'm sorry. sh*t happens, might have been my english that confused me about the meaning of the sentence. Quote Link to comment https://forums.phpfreaks.com/topic/270151-website-scrolls-up-when-buttons-are-pressed/#findComment-1389407 Share on other sites More sharing options...
hahaitwork Posted November 1, 2012 Author Share Posted November 1, 2012 If you don't want to refresh the page when you do something, you HAVE to use javascript. If that something requires working with PHP or MySQL, you HAVE to use AJAX. Well it has to be php and mysql so, ajax it is.. then this problem can't really be solved? it's not a major problem realy, just something I would like to fix if it is possible. Quote Link to comment https://forums.phpfreaks.com/topic/270151-website-scrolls-up-when-buttons-are-pressed/#findComment-1389408 Share on other sites More sharing options...
Jessica Posted November 1, 2012 Share Posted November 1, 2012 I guess you could give each button or link an anchor tag with a name, and then link to the same anchor tag in your link. That is what anchors are for. Quote Link to comment https://forums.phpfreaks.com/topic/270151-website-scrolls-up-when-buttons-are-pressed/#findComment-1389410 Share on other sites More sharing options...
hahaitwork Posted November 2, 2012 Author Share Posted November 2, 2012 I guess you could give each button or link an anchor tag with a name, and then link to the same anchor tag in your link. That is what anchors are for. wouldn't that refresh the website anyhow? Quote Link to comment https://forums.phpfreaks.com/topic/270151-website-scrolls-up-when-buttons-are-pressed/#findComment-1389531 Share on other sites More sharing options...
ManiacDan Posted November 2, 2012 Share Posted November 2, 2012 Ok, for real, read this: In order to perform an action without refreshing the page, you must use javascript. If said action interacts with the server, you must use AJAX. Go read it again to be sure you understand it. Now that you get that: You can use named anchor tags and hash marks in your URLs so that, when you refresh the page, the page automatically scrolls back down to a specific target. This solves what you're complaining about ("page scrolls up") without forcing you to learn and implement ajax. Quote Link to comment https://forums.phpfreaks.com/topic/270151-website-scrolls-up-when-buttons-are-pressed/#findComment-1389604 Share on other sites More sharing options...
hahaitwork Posted November 5, 2012 Author Share Posted November 5, 2012 (edited) Ok, for real, read this: In order to perform an action without refreshing the page, you must use javascript. If said action interacts with the server, you must use AJAX. Go read it again to be sure you understand it. Now that you get that: You can use named anchor tags and hash marks in your URLs so that, when you refresh the page, the page automatically scrolls back down to a specific target. This solves what you're complaining about ("page scrolls up") without forcing you to learn and implement ajax. Okey.. I understood it better now, but I'm not sure how to fix it as my script is like this: This is mainly the parts with + and - and remove. Tried a few things but ending up with errors, it's mostlying trying to set <a name="x"></a> and call it insted of using the $page if (isset ($_GET['add'])) { $quantity = mysql_query ('SELECT id, quantity FROM products WHERE id=' .mysql_real_escape_string ((int) $_GET ['add'])); while ($quantity_row = mysql_fetch_assoc ($quantity)) { if ($quantity_row['quantity'] !=$_SESSION['cart_'.(int)$_GET['add']]) { $_SESSION['cart_'.(int)$_GET['add']]+='1'; } } header('Location: '.$page); } if (isset($_GET['remove'])) { $_SESSION['cart_'.(int)$_GET['remove']]--; header('Location: '.$page); } if (isset($_GET['delete'])) { $_SESSION['cart_'.(int)$_GET['delete']]='0'; header('Location: '.$page); } echo "<p style='width:250px; float:left;'>". '<table border="1" >'.'<tr>'.'<td WIDTH="250px" HEIGHT="80px" float:left; ">'.'<center>'.$get_row['name'].'<br />'.$get_row['description'].'</center>'.'</td>'.'</tr>'.'<td WIDTH="60%" HEIGHT="50px" ">'.'<center>'.' x '.$ids[$get_row['id']].' * €'.number_format ($get_row['price'],0).' = €'.number_format($sub, 0). '</td>'.'</tr>'.'<tr>'.'</center>'.'<tr>'.'<td WIDTH="200px" HEIGHT="0px"'.'<center>' .'          <a href="cart.php?remove='.$get_row['id'].'"><img src="subtract.png" border="0" style="height: 20px; width: 35px" ></a>    <a href="cart.php?add='.$get_row['id'].'"><img src="pluss.png" border="0" style="height: 20px; width: 35px" ></a>    <a href="cart.php?delete='.$get_row['id'].'"><img src="delete.png" border="0" style="height: 20px; width: 50px" ></a></p>' .'</center>' .'</td>' .'</tr>' .'</td>'.'</tr>'.'</table>'; Edited November 5, 2012 by hahaitwork Quote Link to comment https://forums.phpfreaks.com/topic/270151-website-scrolls-up-when-buttons-are-pressed/#findComment-1390322 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.