faqts : Computers : Programming : Languages : JavaScript

+ Search
Add Entry AlertManage Folder Edit Entry Add page to http://del.icio.us/
Did You Find This Entry Useful?

7 of 10 people (70%) answered Yes
Recently 7 of 10 people (70%) answered Yes

Entry

try follwn javacript code in Netscape 6+ alert("a z"), the spaces r truncated

Apr 7th, 2008 23:45
ha mo, Colin Fraser, kuhite k,


Well the question does not make a lot of sense here. Firstly, what 
spaces? The one between the "a" and the "z"? It works for me. You may 
have meant to put into the question " a z " but the results are not 
obvious. However, the alert box obviously truncates the leading spaces 
when I put in "     a z          " into the script. There is no way of 
checking if the trailing spaces are also removed, but I suspect that it 
would be reasonable to assume that they are. 
The only thing I can think of here is that the broswer automatically 
validates the text entered into the alert box's dialog string and if it 
runs into a leading or trailing space then it is removed. It is a 
normal assumption in programming that not all users are able to write 
appropriate code. So to minimise errors, validation code is always 
used. From memory it would be something like 
functin checkstring(alertstring) {
  alertstring= userinput 
  lTrim(alertstring)
  rTrim(alertstring)
 //(or maybe just trim(alertstring)
}
which trims out any spaces from the left or right of the string the 
user enters. IE6 has no such trim function, which was a surprise.
What has always concerned me has been this automatic assumption by the 
vast majority of programmers that they know what their users want 
better than the user him- or her- self, that the user is by definition 
not very smart and cannot work out what they really want. This is the 
sort of arrogance Microsoft in particular has been guilty of for 
decades,(other companies though are just as bad) but it now seems that 
Microsoft is mending some of its ways or maybe someone got lazy or the 
program was just so big that they needed to trim some code out to make 
it work. Who knows!  
In any case, I suspect there is not a lot you can actually do about it.
http://www.businessian.com
http://www.computerstan.com
http://www.financestan.com
http://www.healthstan.com
http://www.internetstan.com
http://www.moneyenews.com
http://www.technologystan.com
http://www.zobab.com
http://www.healthinhealth.com