Go Back   CodingForums.com > :: Client side development > JavaScript programming > JavaScript frameworks

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 10-29-2011, 04:59 PM   PM User | #1
hekowie
New to the CF scene

 
Join Date: Oct 2011
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
hekowie is an unknown quantity at this point
popup makes page scroll - help!

Hello everybody..

I have an add to cart button on my products and when clicked a popup opens that offers a choice to go to the checkout page or continue shopping.
The problem is every time the popup opens the page behind it scrolls to the top. I need the page to stay where the button was clicked and not scroll.

I've found posts where it's suggested to add return false to the onclick. But I tried that and it didn't help. Very possible I didn't do it correctly too.

Can someone please review my code and let me know what I need to do?

Code:
  <script type="text/javascript">

$(document).ready(function() {	

	
		//Get the screen height and width
		var maskHeight = $(document).height();
		var maskWidth = $(window).width();
	
		//Set heigth and width to mask to fill up the whole screen
		$('#mask').css({'width':maskWidth,'height':maskHeight});
		
		//transition effect		
		$('#mask').fadeIn(1000);	
		$('#mask').fadeTo("slow",0.8);	
	
		//Get the window height and width
		var winH = $(window).height();
		var winW = $(window).width();
              
		//Set the popup window to center
		$('#dialog').css('top',  winH/2-$('#dialog').height()/2);
		$('#dialog').css('left', winW/2-$('#dialog').width()/2);
	
		//transition effect
		$('#dialog').fadeIn(2000); 

	//if close button is clicked
	$('.window .close').click(function (e) {
		//Cancel the link behavior
		e.preventDefault();
		
		$('#mask').hide();
		$('.window').hide();
	});		
	
	//if mask is clicked
	$('#mask').click(function () {
		$(this).hide();
		$('.window').hide();
	});			
	
});

</script>



<input type="reset" value="Add to Cart" name="add" onClick="window.location='/Merchant2/merchant.mv?Attributes=Yes&Quantity=1'"/><br/>                 
<input type="reset" value="View Cart" name="view" onClick="window.location='/Merchant2/merchant.mv?Screen=BASK&Store_Code=ST'"/><br/>              
<input type="reset" value="Check Out" name="checkout" onClick="window.location='/Merchant2/merchant.mv?Screen=ERS&Store_Code=ST'"/>
hekowie is offline   Reply With Quote
Old 10-29-2011, 07:23 PM   PM User | #2
VIPStephan
The fat guy next door


 
VIPStephan's Avatar
 
Join Date: Jan 2006
Location: Halle (Saale), Germany
Posts: 7,585
Thanks: 5
Thanked 864 Times in 841 Posts
VIPStephan is a jewel in the roughVIPStephan is a jewel in the roughVIPStephan is a jewel in the rough
Where is the button that invokes the popup (or the script, respectively)?

If the click is invoked with jQuery you can do
Code:
….click(function(e) {
  e.preventDefault();
  …
}
That preventDefault function prevents the default action, i. e. the link going somewhere.

On the other hand, since the anchor isn’t linking anywhere anyway (as I assume by you saying that it jumps to the top which sounds like you have an href="#") you would be better off just removing that attribute altogether. Why have a link that’s not linking anything?
__________________
Don’t click this link!
VIPStephan is offline   Reply With Quote
Old 10-29-2011, 07:45 PM   PM User | #3
hekowie
New to the CF scene

 
Join Date: Oct 2011
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
hekowie is an unknown quantity at this point
Quote:
Originally Posted by VIPStephan View Post
Where is the button that invokes the popup (or the script, respectively)?

If the click is invoked with jQuery you can do
Code:
….click(function(e) {
  e.preventDefault();
  …
}
That preventDefault function prevents the default action, i. e. the link going somewhere.

On the other hand, since the anchor isn’t linking anywhere anyway (as I assume by you saying that it jumps to the top which sounds like you have an href="#") you would be better off just removing that attribute altogether. Why have a link that’s not linking anything?
Yes, I'm assuming it is using jquery because the script shows $(document) etc.
There is no href tag used on the buttons either.

I don't get that click function(e) you posted. Is that what you recommend after my clarification? If so, can you show me the parts you cut out and how it is used?

Thanks
hekowie is offline   Reply With Quote
Old 10-30-2011, 12:34 AM   PM User | #4
VIPStephan
The fat guy next door


 
VIPStephan's Avatar
 
Join Date: Jan 2006
Location: Halle (Saale), Germany
Posts: 7,585
Thanks: 5
Thanked 864 Times in 841 Posts
VIPStephan is a jewel in the roughVIPStephan is a jewel in the roughVIPStephan is a jewel in the rough
Hang on, I’m not getting something here. Are you saying this “add to cart” button is invoking the popup?
Code:
<input type="reset" value="Add to Cart" name="add" onClick="window.location='/Merchant2/merchant.mv?Attributes=Yes&Quantity=1'"/>
Because what I see there is that it just opens a new page.
It would be really great to see a live example.
__________________
Don’t click this link!
VIPStephan is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 11:53 AM.


Advertisement
Log in to turn off these ads.