Category Archives: Dhtml

Dead Center DIV

body {
margin: 0px
}

#horizon {
color: white;
background-color: #0ff;
text-align: center;
position: absolute;
top: 50%;
left: 0px;
width: 100%;
height: 1px;
overflow: visible;
visibility: visible;
display: block
}

#content {
position: absolute;
left: 50%;
width: 250px; /* Overall width of div */
height: 70px; /* Overall height of div */
top: -35px; /* half of the overall height */
margin-left: -125px; /* half of the overall width */
visibility: visible
}

Retain scroll position after browser refresh

Retain scroll position after browser refresh
As Joel Spolsky points out, updating web pages by getting just the bits of information that have changed instead of refreshing the whole page is the wave of the future. Whether we’re calling web services within a client-side page or using a gmail-like JavaScript technique (darn cool), it’s going to be a major architectural shift. It’s going to be hard.

In the meantime, there is a really easy way to fix the problem of having to scroll back down to the part of the page you were using when a refresh occurred. Because ASP.NET’s post-back model forces a trip to the server for anything interesting to happen, this technique is essential if you’re using ASP.NET. However, it works just as well in Perl, PHP, JSP – whatever your server-side technology. It requires client-side JavaScript to be enabled, but so do the fancier techniques we are looking forward to.
Note that you could also just turn “smart navigation” on in ASP.NET, but I’ve had issues where smart navigation messes up other JavaScript. I prefer not to use it.
I’ve implemented an example of the technique for this post separately in PHP and ASP.NET/C#. You can see the PHP example in action or download a zip file of the ASP.NET/C# example. For both examples, I use hidden fields and client-side script. They imply an http POST, and typically you will be posting to the same page. You could make it work with GET and/or with another page, but the problem itself gets more confusing in those scenarios.

Here is the complete PHP example:

Continue reading Retain scroll position after browser refresh

Button Submit Once!

In a web application where the users are real dum the ussualy double click in buttons so the filled forms are submitting more than 1 time. Here is the script to prevent that.

<!--more-->
/*
Submit Once form validation-
© Dynamic Drive (www.dynamicdrive.com)
For full source code, usage terms, and 100's more DHTML scripts, visit http://dynamicdrive.com
*/

function submitonce(theform){
	//if IE 4+ or NS 6+
	if (document.all||document.getElementById) {
		//screen thru every element in the form, and hunt down "submit" and "reset"
		for (i=0;i&lt;theform.length;i++){
			var tempobj=theform.elements[i]
			if(tempobj.type.toLowerCase()=="submit"||tempobj.type.toLowerCase()=="reset")
			//disable em
			tempobj.disabled=true
		}
	}
}
</script>
 <form method="POST" onSubmit="submitonce(this)"> 

jQuery a great tool for any ServerSide Scripting Language

logo

One of the most used framework for making your web application more live, interactive. There is been a while since I run into it, but recently I decided to use it. Main reason is when i saw the sits that actually use the jQuery framework. Take a look here and you ll be suprised by the big company names.

Continue reading jQuery a great tool for any ServerSide Scripting Language