SitePoint Sponsor |
|
User Tag List
Results 1 to 3 of 3
Thread: form submission and return false
-
Jan 20, 2009, 14:16 #1
form submission and return false
I have a small search appliance on my site that uses the following HTML:
Code:<form action="/search/search.aspx" method="post" onsubmit="siteSearch(this);"> <input name="q" id="searchbox" type="text" value="Search..."> <input type="hidden" id="search-url" value="/search/search.aspx"> <input type="submit" class="search" name="submit" id="search-submit" value="GO"> </form>
Code:function siteSearch(form) { var q = $("#searchbox").attr("value"); var url = $("#search-url").attr("value"); if (q == "Search...") { alert("Please enter search criteria."); return false; } form.action = url + "?q=" + q; return true; }
Any ideas on how to stop the action in the form?
-
Jan 20, 2009, 14:34 #2
- Join Date
- Mar 2008
- Location
- NP, New Zealand
- Posts
- 576
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
-
Jan 20, 2009, 15:13 #3
- Join Date
- Jan 2007
- Location
- Christchurch, New Zealand
- Posts
- 14,729
- Mentioned
- 104 Post(s)
- Tagged
- 4 Thread(s)
Yes, you need the return so that the value returned from the function is itself returned to the form.
Programming Group Advisor
Reference: JavaScript, Quirksmode Validate: HTML Validation, JSLint
Car is to Carpet as Java is to JavaScript
Bookmarks