0

I have a form that I want to default to calling a javascript ajax function to get the output. If the user doesn't have javascript enabled, I need to be able to recognize that and change the form action to a php page. Any idea on how to do this?

<form class="form-inline" role="form" action="javascript:search();">
  <div class="form-group">
    <label class="sr-only" for="search">Search</label>
    <input type="text" class="form-control" id="search" placeholder="Search">
  </div>
  <button type="submit" class="btn btn-default">Search</button>
</form>

search() will get the form input and get the output through ajax without reloading the page. If javascript is not enabled, I will need to change the action to just search.php.

1 Answer 1

3

By default set action to search.php

if client JavaScript is enabled below code will change action

$(function () {
    $('.form-inline').prop('action', 'javascript:search();');
});
Sign up to request clarification or add additional context in comments.

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.