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 6155753
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T20:29:27+00:00 2026-05-23T20:29:27+00:00

var inpt = $(‘#input-box’).val(); if (inpt != ”) { $(‘form’).submit(); alert(‘Voila!’); // (1) }

  • 0
var inpt = $('#input-box').val();
if (inpt != '') {
    $('form').submit();
    alert('Voila!');           // (1)
} else {
alert('fill something man');   // (2)
}

I am using this code to automatically submit the form as soon as the page loads.
Here I am unable to use the jquery $(document).ready() function because I m in GreaseMonkey environment.
The form is automatically filled, I used (2) statement for exceptional cases.

I get no alerts! neither from (1) nor from (2).

UPDATE:

    <label for="answer">Answer:</label>
    <input type="text" name="answer" id="input-box" />
    <input type="submit" name="submit" id="submit" value="Submit" />
</form>
  • 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-23T20:29:30+00:00Added an answer on May 23, 2026 at 8:29 pm

    Try to put the alert before the submit.

    var inpt = $('#input-box').val();
    if (inpt != '') {
        alert('Voila!');           // (1)
        $('form').submit();
    } else {
        alert('fill something man');   // (2)
        return false; // to stop submitting
    }
    

    If you want it to auto-submit after a user enter a value then you can do thsi:

    $('#input-box').live('blur',function(){
    
        var inpt = $('#input-box').val();
        if (inpt != '') {
            alert('Voila!');           // (1)
            $('form').submit();
        } else {
            alert('fill something man');   // (2)
            return false; // to stop submitting
        }
    
    });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

var query1 = urlencode($('input[name=searchTerm1]').val()); //user1 var query2 = urlencode($('input[name=searchTerm2]').val()); //user1 var rpp = 20;
var query1 = urlencode($('input[name=searchTerm]').val()); //user1 $.getJSON('http://twitter.com/friends/ids.json?screen_name='+ query1 +'&jsoncallback=?', function(data){ $('content').append(''+data.length+''); }); This is a
var input; // method 1 input = document.getElementById('address').value; alert(input) // method 2 eval('input =
var thumbs = document.getElementsByTagName(img); for (var i=0; i<thumbs.length; i++) { Core.addEventListener(thumbs[i], click, function() {alert(i);});
var $imagefile = $('<input />') .attr({ type: 'file', name: 'imageFile', id: 'imageFile' }); Above
var allRapidSpells = $$('input[value^=RSW]'); Can anyone tell me what that does?
var mychars = 'abcdefghijklmnopqrstuvwxyz'; for (i = 0; i < mychars.length; i++) { alert(i.toString()
var currentClassName = $(this).parent('td').next('td').find('input:text').attr('class'); if (currentClassName == undefined) { currentClassName = $(this).parent('td').find('input:text').attr('class'); } This
var regExpress = /^([a-zA-Z0-9\!\@\#\$\%\^\&\*\(\)\-\+\=\|\}\{'\\;\:\?\/\.\,\s]*)/i; if (strMessage.search(regExpress) == -1) { alert(error occurs); } I want
var f = function() { // Do something useful here }; Is there a

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.