Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6885797
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T05:40:45+00:00 2026-05-27T05:40:45+00:00

Consider the following script for checking if search form is empty. The id’s of

  • 0

Consider the following script for checking if search form is empty. The id’s of search buttons are: mainSearch and searchIcon

    <script type="text/javascript">
    $(document).ready(function() {
        $('#mainSearch').click(function() {
                if($("input[type=text][name=search]").val() == "" || $("input[type=text][name=search]").val() == 'Напишете търсената дума'
                || $("input[type=text][name=search]").val() == 'Enter search keywords here')
                    return false;
        });
    });
    $(document).ready(function() {
        $('#searchIcon').click(function() {
                if($("input[type=text][name=q]").val() == "" ) 
                    return false;
        });
    });
    </script>

HTMLscheme:

<div class="searchForm">
            <form action="search.php" method="get">
                <input type="text" name="search" id="searchForm" value="<?php if(checkBgLanguage()) echo 'Напишете търсената дума'; else echo 'Enter search keywords here'; ?>" autocomplete="off"
                maxlength="35"/>
                <a href="search.php"><img src="css/imgs/searchIcon.png" width="24" height="24" id="mainSearch"/></a>
            </form></div>

For some reason the second function is working on every page. The first function works only on the home page. Another problem is pressing enter button; nobody should submit clear form with enter. Any help is greatly appreciated.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T05:40:46+00:00Added an answer on May 27, 2026 at 5:40 am

    You should put both those functions into a single $(document).ready(){} block, as each block will slow down your page by binding the event respectively. You can also use the shorthand $(function(){});. From there, try event.preventDefault() instead of returning false:

    $(function(){
        $('#mainSearch').click(function(event) {
            var val = $("input[type=text][name=search]").val();
            if(val == "" || val == 'Напишете търсената дума'
                ||val == 'Enter search keywords here') {
                event.preventDefault();
            }
        });
    
        $('#searchIcon').click(function(event) {
            var val = $("input[type=text][name=q]").val();
            if(val == "" ) {
                event.preventDefault();
            }
        });
    });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Consider the following document <html> <body> This is some content <script type=text/javascript src=verySlowToRespond.js></script> This
Consider the following example: <html> <body> <script type=text/javascript> var str=filename.jpg; var pattOne = new
Consider the following html snippet <!DOCTYPE html> <html> <head> <script type=text/javascript src=http://code.jquery.com/jquery-1.4.2.js ></script> <script
Consider the following piece of code: <html><head></head> <body> <script type=text/javascript> var outside_scope = outside
Consider two web pages with the following in their body respectively: <body> <script> document.writeln('<textarea></textarea>')
Consider the following HTML: (Written for Google Chrome) <html> <head> <script language=javascript> function AddToIFrame(){
Consider the following script: println ls -l.execute().text Why do I get the following error
consider the following code: <script> function testFunc(){ alert('test') } $(function(){ var g = document.getElementById
Please consider the following scenario with a simple HTML document and a JavaScript loaded
Consider the following script for outputting some XML code: var xmlAsString = '<?xml version=1.0?><person><name

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.