Sorry, this entry is only available in Español.
Change Language
Physics
Research
-
Recent Posts
Categories
Archives
Sorry, this entry is only available in Español.
Sorry, this entry is only available in Español.
Sorry, this entry is only available in Español.
Sorry, this entry is only available in Español.
Sorry, this entry is only available in Español.
Let’s contribute to some programming habits that might help every member of the community:
1. When you detect a mistake of something nonsense, that used to work BEFORE, THEN DON’T START OVER. Some people prefer to repeat the process from the beginning, wanting that the second time everything will go better. Don’t do that. Seek for the mistake, and LEARN from it. In that way, the next time it occurs, you will find it quicker, and you will trust both in the technology and, more important, in your own developments.
Remember there are several ways to obtain the height of a body object, and one of those ways is using the instruction
<blockquote>alert(document.documentElement.scrollHeight);</blockquote>
However, I began to obtain “0″ for this instruction, in spite I was sure it was working in my server, in an application I was building. I felt very curious about this, so the solution was to re-load an old version from my server, download it using the Mozilla-Firefox browser, and compare it with the new one that was failing <a href=”http://investigacionyprogramacion.com/wordpress/?p=61&lang=en”>See: habits for good programming</a>.
But when I tested the new downloaded file, it worked!!! So its code was alright. However, the new version was still failing. So I came to the new version, and studied the code directly from Firefox’s source code viewer. I noted this:
<blockquote>
<script language=”javascript”>
alert(document.documentElement.scrollHeight);
</script>
<!DOCTYPE HTML PUBLIC “-//W3C//DTD XHTML 1.0 Transitional//EN” “http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd”>
<html xmlns=”http://www.w3.org/1999/xhtml”><head><meta http-equiv=”Content-Type” content=”text/html; charset=ISO-8859-1″><title>POBOXTORE</title></head><body id=”_”>
….[[and other stuff]]
</blockquote>
As you can see, there is a <script></script> block BEFORE the <html> tag. If you do this, you are going to retrieve “0″ as the result of
<blockquote>alert(document.documentElement.scrollHeight);</blockquote>
If you use “javascript:alert(document.documentElement.scrollHeight);” in your address bar, it will fail also. So the explanation was very simple, but a little tricky to trace, because when you use mozilla-firefox to save a page whose structure is
<script></script><html><head> ….
then Mozilla-Firefox changes to this one when saving it:
<html><head> <script></script> ….
So your saved file WILL work although the exact same file when seen directly in the server doesn’t work.
Last, but not least: it doesn’t matter WHAT BLOCK you have before <html><head>. If you put <invented block>anything</invented block>, it will fail also.
<strong><span style=”font-size: 3Em”>Problem solved.</span></strong>
By the way, one last comment about this instruction, of retrieving body’s height. I’ve been using successfully these lines, for browser compatibility:
<blockquote>
<SCRIPT type=”text/javascript” language=”javascript”>
if (navigator.userAgent.toString().indexOf(“Chrome”)==-1) {
height = document.documentElement.scrollHeight;
} else { //If it’s google Chrome:
height = document.body.scrollHeight;
}
</blockquote>
I hope this will be useful for a few people.
Best Regards,
Investigación y Programación Ltda.
This post exists only in Spanish. Please read it here: http://investigacionyprogramacion.com/wordpress/?p=39&lang=es
Let’s say we want to write a Dropdownlist using Yii, for example:
How can we set a default selected value? There are several methods. I’m gonna begin with the two methods that I like the least (I don’t like them, but nonetheless they are illustrative), and the 3rd one is the method I recommend.
1. Changing the model’s attribute, but it has the problem of not being the best solution if the dropdownlist is multiselect. Besides, it is a model level solution for an interface issue: unless we are talking about a very sensitive decision, sometimes the default-selection is a matter of visualization only, sometimes it is a programmer’s whim to leave a default selection, but it doesn’t deeply affect the database, nor the model itself, nor the application gravely, so I think that the solution should be in the views layer.
2. Creating a default value in the table, is another solution that is being proposed in other threads.
This is worse, I think: it uses a database-level solution for something that is a matter of visualization (read the argument of point 1).
3. A views’ level solution, is using the “options” entry in the array of htmloptions, I read it in the CHtml Dropdownlist (http://www.yiiframew…DownList-detail) documentation, but I applied it for an ActiveForm Dropdownlist. So in this example, if the reader wants the item with key value “2″ to be selected by default, she/he should use: