Page 1 of 2
ajax? Javascript? forms?
Posted: Sun Nov 25, 2007 10:06 am
by FireElement
I just wondered? Does ajax relay on javascript been turned on!
I read the advantages of ajax and I though they sounded good but a lot of people say dont relay on javascript... So I was wondering if ajax relayed on javascript...
Also I would like to know why its a bad idea.... I mean I build sites not to relay on it, how ever when I make forms I general relay on it a lot. Infact most my forms would probabl not work with out it... eg for submiting.
Just wondered if this was a bad thing? also if so how can I build one that does not realy on it? I heard something about DHTML...
I use php a lot but I know this may be out of scope been php site but figured might as well ask!
Thanks!
Posted: Sun Nov 25, 2007 11:10 am
by Josh1billion
DHTML is just a word for using Javascript and HTML together (it stands for Dynamic HTML).
When you say "relay," I think the word you're looking for is "rely," so I'll answer based on that. Ajax does rely on Javascript because Ajax is a part of Javascript, so if your user has Javascript turned off, that would definitely be a problem if your site is Ajax-based. But how many of your users have Javascript turned off? Should be some statistics somewhere for how much of the general population uses Javascript, and I think only a small fraction browse with it off. I could be wrong on that though. But if you're thinking about just throwing out Javascript and Ajax entirely because a small fraction of your users don't support Javascript, you have to ask yourself: would you completely ignore CSS just because a fraction of your users still use IE6?
I say if it greatly improves your site's functionality, go for it and use Ajax/Javascript. Better to have an awesome product that 95% of everyone can use than a mediocre product that 99% can use, in my opinion.
But of course, if it's not too much trouble, you'd also want to write alternative code for users who don't have Javascript enabled so that they don't just get shut out. But if your site is entirely Ajax-based, that could be more trouble than it's worth.
Posted: Sun Nov 25, 2007 12:48 pm
by feyd
In many jurisdictions it's illegal to require Javascript due to accessibility laws.
Posted: Sun Nov 25, 2007 12:51 pm
by CoderGoblin
One common expression I like to use is "site enhanced by javascript". The <noscript> HTML tag can be very useful. An example ... using AJAX only a part of a page could be updated. When javascript is off the user has a button which reloads the entire page with the relevent information. This button is not visible when users have javascript. As well as AJAX another thing to always be aware of is javascript based menus if you use them. They must also degrade properly. Also if you use javascript to validate forms, the checks need to be performed on the server side as well (PHP). This needs to always be done anyway as the javascript check can be bypassed easily.
An example of AJAX handling is contained in
Dynamic/Chained Selects using Ajax Prototype/JQuery where matthijs correctly pointed out that there was a requirement to cope when javascript was switched off.
Oh, one statistic I read (Jan 2007) had 6% of people with javascript switched off. That could relate to a fair amount of business .

Thanks all posters!
Posted: Sun Nov 25, 2007 5:03 pm
by FireElement
Well thanks that helped clear a lot up!!!
I did mean rely! I am dyslexic. haha... errr...
Anyways Yeah I use php to validate everything on my site and checked it cant be hacked by downloading the page changing the javascript and posting it to the same page. I have a hidden form that posts the info to the next page and on the next page I have the script in php to send it to sql server so you cant bipass it with out hacking I dont thinks.
I have lot of stuff though that gets sent via javascript to check its on and is the right format, so I can access stuff on refresh or submit say if the php verifier goes no thats wrong... Change it idiot bot! Ironically a computer telling the user what to do, a tool becoming a instructor! haha.
Anyways back to point! I have javascript passing info to php thats all integrating them together. I also lately created a javascript drop down box that allowed the user to select stuff from the server without it refreshing. Although ajax is good at this I wanted to get better at javascript so I set out to do it like this. Next I will learn ajax!
I only make the site rely on javascript in forms but not in general the general checks are done by php meaninf they cant just by pass it by saving the page and sending it back to the page!
But in general the site should work with it switched off althought they wont be able to add anything via forms... Maybe I should change that? Is there away to make chained select boxes call from a server with out using javascript? I cant think of out... with out the site not been dynamic and enering everthing in manually and yawn!
I think most the people who use my site will have it installed.... :s
Also on side note is there away to turn javascript off so I can check! Whats what... Just for wondering sake!
Posted: Sun Nov 25, 2007 6:52 pm
by superdezign
JavaScript is not "installed," but is interpreted and ran line by line by the user's browser.
And you can turn JavaScript off via Tools > Options > Content > Enable JavaScript in Firefox, and I think it's in Tools > Internet Options > Advanced in Internet Explorer (though I'm not 100% positive).
Posted: Sun Nov 25, 2007 9:01 pm
by alex.barylski
I have personally made the choice quite a while ago to support a basic system - only using JS, etc when it's available. First instance, throwing a confirmation dialog when someone is about to delete.
??
Posted: Sun Nov 25, 2007 9:36 pm
by FireElement
What you mean? only using JS? Why?
Would that not be risky?
Posted: Sun Nov 25, 2007 9:43 pm
by FireElement
superdezign wrote:JavaScript is not "installed," but is interpreted and ran line by line by the user's browser.
And you can turn JavaScript off via Tools > Options > Content > Enable JavaScript in Firefox, and I think it's in Tools > Internet Options > Advanced in Internet Explorer (though I'm not 100% positive).
Thanks, I used the wrong word there. Meant enabled. So why would a user dissable javascript? what would be the point?
Re: Thanks all posters!
Posted: Sun Nov 25, 2007 10:02 pm
by CoderGoblin
FireElement wrote:I have a hidden form that posts the info to the next page and on the next page I have the script in php to send it to sql server so you cant bipass it with out hacking I dont thinks.
Have you thought of using php sessions ?
FireElement wrote:But in general the site should work with it switched off althought they wont be able to add anything via forms... Maybe I should change that? Is there away to make chained select boxes call from a server with out using javascript? I cant think of out... with out the site not been dynamic and enering everthing in manually and yawn!
If they can't add anything using forms does this mean the site doesn't work. Remember if someone leaves your site because it doesn't work they stand a good chance of never coming back. As for chained selects... the only way outside of javascript is to reload the entire page... Look at the link I provided earlier for example.
People have javascript off mainly for security reasons, others to speed up browsing. Look at a lot of sites coming into play now and they crawl, not because of the information but because of all the javascript behind it. Also javascript cannot be guaranteed when thinking about accessibilty (the disabled).
It is always easier to build a site without javascript and then enhance it (also called hijacking) then build it relying on javascript then get it working without.
Posted: Sun Nov 25, 2007 10:04 pm
by s.dot
Asynchronous
Javascript And XML

Posted: Sun Nov 25, 2007 11:20 pm
by alex.barylski
What you mean? only using JS? Why?
Would that not be risky?
Not sure if that was directed at me or not, but...
Why would supporting JavaScript if it was only available be risky? On the contrary, having an application interface which relies on javascript is risky.
Goto facebook.com and browse around weith javascript disabled and you should encountered some sections which cannot be accessed without javascript.
In my applications I check for the existance of javascript using a 1x1 pixel image in the login screen wrapped inside <noscript> tags
Code: Select all
<noscript>
<img src="images/checkjs.php" />
</noscript>
After that point my application cen determine iof JavaScript is enabled and allow for a more advanced interface such as using JS powered menus, confirmation dialogs, using AJAX to update screen sections, etc. If Javascript is disabled the application just falls on the default interface which assumes nothing about the environment. This way I support as many users as possible.
Posted: Mon Nov 26, 2007 12:44 am
by Josh1billion
Hockey wrote:In my applications I check for the existance of javascript using a 1x1 pixel image in the login screen wrapped inside <noscript> tags
Code: Select all
<noscript>
<img src="images/checkjs.php" />
</noscript>
Very clever technique.

Posted: Mon Nov 26, 2007 2:58 am
by matthijs
In my opinion you should almost never rely on javascript. The key words here are: unobtrusive javascript, graceful degradation and progressive enhancement. Meaning, you build your webpage/app in a way not relying on javascript. Only when javascript is available, do you make use of it.
When you would build a page with a form, you build it by reloading the page. Then, you use javascript to "hijack" the form's action. Meaning, when javascript is turned on, disable the normal action and let the form be submitted by js.
A few good resources to learn more about this are:
http://www.onlinetools.org/articles/uno ... avascript/
http://www.alistapart.com/articles/behavioralseparation
http://www.webreference.com/reviews/dom_scripting/
So even the noscript tag is not needed/wanted. Just as you don't want any inline styles or presentational stuff in your html, you don't want to mix the behavior layer into the html.
Re: Thanks all posters!
Posted: Mon Nov 26, 2007 8:27 am
by FireElement
Have you thought of using php sessions ?
Yes I was going to do that today as I realised that it was stupid not to! I was just reading some tutorials on it.
I original built it been ignorant to javascript... Mainly because like you said it makes it slow and well I wanted to not use it. I then later realised it had its uses.
I dont know how to make the page refresh on select of a select box with out using javascript. I also dont know how to get a page to foward to another page on refresh if the form is complete again without changing the action using javascript. Maybe there is away to do it in php which I did not realise. Also I dont know how to automatically get a form to submit with out using javscript.
EDIT:
There is away actual but it relays on refreshing the page on select box select... is there away to refresh the page with out using javascript....
EDIT
To be honest I know some of my code is bit lose and I made mistakes but I also know I never done a site as complex as I am at the minute so... Its all in the learning and I also knowI can go back over code as I improve and change it.
At the minute I am a bit worried about losing users who dont use javascript.... but all in the due learning process I guess....
Not sure if that was directed at me or not, but...
Sorry miss read what you put it was late in england and I read it as only using JS not only using it if nessary... I also want to do this in the future but at the minute working with a lot of forms and trying to keep the site dynamic as in creating its own pages based on the categories created by the web site master. I am finding it hard.
Thanks I be sure to read them
