ajax? Javascript? forms?
Moderator: General Moderators
-
FireElement
- Forum Commoner
- Posts: 86
- Joined: Wed Oct 17, 2007 6:03 pm
ajax? Javascript? forms?
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!
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!
- Josh1billion
- Forum Contributor
- Posts: 316
- Joined: Tue Sep 11, 2007 3:25 pm
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.
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.
- CoderGoblin
- DevNet Resident
- Posts: 1425
- Joined: Tue Mar 16, 2004 10:03 am
- Location: Aachen, Germany
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 .
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 .
-
FireElement
- Forum Commoner
- Posts: 86
- Joined: Wed Oct 17, 2007 6:03 pm
Thanks all posters!
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!
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!
- superdezign
- DevNet Master
- Posts: 4135
- Joined: Sat Jan 20, 2007 11:06 pm
-
alex.barylski
- DevNet Evangelist
- Posts: 6267
- Joined: Tue Dec 21, 2004 5:00 pm
- Location: Winnipeg
-
FireElement
- Forum Commoner
- Posts: 86
- Joined: Wed Oct 17, 2007 6:03 pm
??
What you mean? only using JS? Why?
Would that not be risky?
Would that not be risky?
-
FireElement
- Forum Commoner
- Posts: 86
- Joined: Wed Oct 17, 2007 6:03 pm
Thanks, I used the wrong word there. Meant enabled. So why would a user dissable javascript? what would be the point?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).
- CoderGoblin
- DevNet Resident
- Posts: 1425
- Joined: Tue Mar 16, 2004 10:03 am
- Location: Aachen, Germany
Re: Thanks all posters!
Have you thought of using php sessions ?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.
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.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!
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.
Asynchronous Javascript And XML 
Set Search Time - A google chrome extension. When you search only results from the past year (or set time period) are displayed. Helps tremendously when using new technologies to avoid outdated results.
-
alex.barylski
- DevNet Evangelist
- Posts: 6267
- Joined: Tue Dec 21, 2004 5:00 pm
- Location: Winnipeg
Not sure if that was directed at me or not, but...What you mean? only using JS? Why?
Would that not be risky?
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>- Josh1billion
- Forum Contributor
- Posts: 316
- Joined: Tue Sep 11, 2007 3:25 pm
Very clever technique.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>
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.
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.
-
FireElement
- Forum Commoner
- Posts: 86
- Joined: Wed Oct 17, 2007 6:03 pm
Re: Thanks all posters!
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.Have you thought of using php sessions ?
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....
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.Not sure if that was directed at me or not, but...
Thanks I be sure to read themA 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/
Last edited by FireElement on Mon Nov 26, 2007 8:37 am, edited 2 times in total.