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? 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 On 11/1/2012 at 9:31 AM, hahaitwork said: 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? 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 ;\ 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. 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 On 11/1/2012 at 9:59 AM, Beeeeney said: 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 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 On 11/1/2012 at 10:29 AM, hahaitwork said: 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. 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 On 11/1/2012 at 11:15 AM, Beeeeney said: 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); } 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. 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 On 11/1/2012 at 2:20 PM, ManiacDan said: 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']. '"> 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? 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 On 11/1/2012 at 2:39 PM, Jessica said: OP, are you being deliberately obtuse? I don't think so, considering the spelling of the word "Example". 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. 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 On 11/1/2012 at 3:36 PM, ManiacDan said: 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? 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 On 11/1/2012 at 3:19 PM, Beeeeney said: 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. 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. 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 On 11/1/2012 at 4:27 PM, hahaitwork said: 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. 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 On 11/1/2012 at 5:27 PM, Beeeeney said: 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. 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 On 11/1/2012 at 4:56 PM, Jessica said: 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. 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. 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 On 11/1/2012 at 8:08 PM, Jessica said: 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? 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. 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 On 11/2/2012 at 1:12 PM, ManiacDan said: 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>'; 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
Archived
This topic is now archived and is closed to further replies.