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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T06:01:15+00:00 2026-06-04T06:01:15+00:00

I have a form, an input and a link. If the input has no

  • 0

I have a form, an input and a link. If the input has no value, clicking the link would direct to a certain url. If the input is NOT empty, then the click would have to submit the form. This is how the link looks like:

<li class="youtube"><a href="#">YouTube</a></li>

This is what I have so far in Jquery:

$('.youtube').bind('click', function() {
    if($(input).val() == ''){
        $(".youtube a").attr("href", "http://www.youtube.com/")
    }else{
      $(form).attr("action","http://www.youtube.com/results?search_query=");
      $(form).submit();
    }

});

This doesn’t work, I can’t figure out why.

  • 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-06-04T06:01:17+00:00Added an answer on June 4, 2026 at 6:01 am

    You want to be targetting the link rather than the li

    I.E.

    $('.youtube a').bind('click') etc..

    Also have you got multiple input fields? Your input field needs to be in quotes otherwise you’re targetting a variable, i.e. ‘input’

    To check for an empty string i’d just do:

    if(!$('input').val())
    {
        // Rest of code here
    }
    

    So your full code would be:

    $('.youtube a').bind('click', function() {
        if(!$('input').val()){
            $(".youtube a").attr("href", "http://www.youtube.com/")
        }else{
          $('form').attr("action","http://www.youtube.com/results?search_query=");
          $('form').submit();
        }
    
    });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a form 'ChallengeType'. Which has these fields: 1) Embedded form team1 input
I have form with multiple input type=radio with text next to them. I want
I have a form with input type=file and another input type=submit . I hide
I have a form with input fields and a button which fades in when
I am using Codeigniter framework and I have a form with input fields. When
My input tag started to go crazy... I have html form for input to
I have an input form with two textareas allowing a user to type in
I have a dijit.form.NumberTextBox input field that starts out with these parms: new dijit.form.NumberTextBox({
I have a form with some input texts passed in GET, and i don't
i have form with user data to input and javascript ajax to send information

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.