Go Back   CodingForums.com > :: Client side development > JavaScript programming > DOM and JSON scripting

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 11-27-2012, 04:15 PM   PM User | #1
kraftomatic
Regular Coder

 
Join Date: Jul 2003
Posts: 593
Thanks: 16
Thanked 0 Times in 0 Posts
kraftomatic is an unknown quantity at this point
Check Value / Set HTML Anchor on Page Load

Hey All,

I've got an older JS page that has several buttons on it to dynamically add and remove sections to a page for editing. Each button click for this submits the form and reloads the page, to the top - well off where the section was just added or deleted. What I want to do is have the page go down to that new section once the page is loaded, which I anticipate doing with anchors. However with the page loading/refreshing every time a section is added or deleted, this makes things a little more difficult.

The JS functions I have now look something like this:

Code:
function add(){
		document.forms[0].process.value = 'add';
		document.forms[0].submit();
	}

function delete(){
		document.forms[0].process.value = 'delete';
		document.forms[0].submit();
	}
On the page load, I could check what value was submitted ('add' or 'delete' here) and then based on that, move the page down to where an anchor is set on it. Does that seem feasible?

There are a number of functions like this scattered throughout multiple pages, so I can't redo it all, adding and removing sections dynamically, unfortunately.

Any suggestions would be greatly appreciated.

Thanks.
kraftomatic is offline   Reply With Quote
Old 11-30-2012, 10:54 AM   PM User | #2
niralsoni
Regular Coder

 
Join Date: Mar 2008
Location: London
Posts: 129
Thanks: 1
Thanked 31 Times in 31 Posts
niralsoni is an unknown quantity at this point
try to set focus on the element that has been added dynamically. It should work...
niralsoni is offline   Reply With Quote
Old 11-30-2012, 01:30 PM   PM User | #3
WolfShade
Regular Coder

 
Join Date: Apr 2012
Location: St. Louis, MO, USA
Posts: 946
Thanks: 7
Thanked 97 Times in 97 Posts
WolfShade is an unknown quantity at this point
If you're using jQuery, you can dynamically find the last element and scroll to it.
__________________
^_^

If anyone knows of a website that can offer ColdFusion help that isn't controlled by neurotic, pedantic jerks* (stackoverflow.com), please PM me with a link.
*
The neurotic, pedantic jerks are not the owners; just the people who are in control of the "popularity contest".
WolfShade is offline   Reply With Quote
Old 12-03-2012, 01:43 PM   PM User | #4
kraftomatic
Regular Coder

 
Join Date: Jul 2003
Posts: 593
Thanks: 16
Thanked 0 Times in 0 Posts
kraftomatic is an unknown quantity at this point
Quote:
Originally Posted by WolfShade View Post
If you're using jQuery, you can dynamically find the last element and scroll to it.
The page isn't using jQuery, that's part of the problem. It would have to be rewritten otherwise.

The page reloads after something has been added/removed, so checking the status on the reload is the tricky part.
kraftomatic is offline   Reply With Quote
Old 12-03-2012, 06:39 PM   PM User | #5
felgall
Master Coder

 
felgall's Avatar
 
Join Date: Sep 2005
Location: Sydney, Australia
Posts: 5,452
Thanks: 0
Thanked 498 Times in 490 Posts
felgall is a jewel in the roughfelgall is a jewel in the roughfelgall is a jewel in the rough
Simply give each form an id - that makes it easier to reference the fields in the form and also provides an anchor point to link back to afterwards.
__________________
Stephen
Learn Modern JavaScript - http://javascriptexample.net/
Helping others to solve their computer problem at http://www.felgall.com/
felgall is offline   Reply With Quote
Old 12-17-2012, 04:44 PM   PM User | #6
kraftomatic
Regular Coder

 
Join Date: Jul 2003
Posts: 593
Thanks: 16
Thanked 0 Times in 0 Posts
kraftomatic is an unknown quantity at this point
Okay, thanks so far guys. With using old-school Javascript, window.hash doesn't work in IE7 which is a problem. So I'm trying to do this in Prototype now (still can't use jQuery). I have a function that will scroll on click, but I can't get it working dynamically when the page loads. Does anyone see what I might need to make this work?

Code:
Event.observe(window, 'load', function() {
	$$('a[href^=#]:not([href=#])').each(function(element) {
		element.observe('click', function(event) {
			new Effect.ScrollTo("newID_1");
			Event.stop(event);
		}
		.bindAsEventListener(element))
	})
})
Thanks a bunch for any suggestions.
kraftomatic is offline   Reply With Quote
Old 12-17-2012, 07:51 PM   PM User | #7
felgall
Master Coder

 
felgall's Avatar
 
Join Date: Sep 2005
Location: Sydney, Australia
Posts: 5,452
Thanks: 0
Thanked 498 Times in 490 Posts
felgall is a jewel in the roughfelgall is a jewel in the roughfelgall is a jewel in the rough
There's no such thing as window.hash = the field you are after is location.hash
__________________
Stephen
Learn Modern JavaScript - http://javascriptexample.net/
Helping others to solve their computer problem at http://www.felgall.com/
felgall 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 12:40 PM.


Advertisement
Log in to turn off these ads.