0

I am currently submitting a form using form action to a php script and i was going to implement ajax form submission also.

But a thought came to my mind that wouldn't it be nice to know if the client's browser has javascript enabled or disabled and submit the form accordingly as i don't want the no-javascript users to view a page that says "Enable Javascript or something"! as i have used both client and server side validations.

So, how should i know that a client has javascript and let him submit form by ajax and vice versa?

I found many QA's related to redirecting users to a page that says "Javascript disabled" and they mostly talked about tags.

I would appreciate hearing you guys and your suggestions. Thankyou :)

2 Answers 2

2

Use a form with a submit button.

In your javascript script put an handler on it, and call the preventDefault function to let your ajax code do the job.

So if javascript is enabled it will submit with ajax. If not it will submit it the default way .

EDIT:

Here is a jsfiddle to illustrate it: http://jsfiddle.net/CTwx2/

Basically the default behavior of a submit button is to send the data to the address indicated in the form tag.

With the handler defined in javascript & jquery, you stop this behavior and send the data by yourself through an ajax request (http://api.jquery.com/event.preventDefault/)

Sign up to request clarification or add additional context in comments.

2 Comments

Will you enlighten me little more? Like @isJustMe said, i don't want to have 2 versions of same thing! But this method sounds good. But what will be the function of preventDefault?
Ah! Thanks a lot. It's not that difficult than what i thought :D I hope it works for me later!
1

You will have to have 2 versions of your site and redirect accordingly using :

<noscript>
  <meta http-equiv="refresh" content="0;url=noscript.html">
</noscript>

OR

Wrap your form in your <noscript> tags, and if javascript is enabled disable that form-

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.