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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T12:59:19+00:00 2026-06-08T12:59:19+00:00

Yo! I have the following function implemented on my site, which allows the user

  • 0

Yo!

I have the following function implemented on my site, which allows the user to press up/down to fluidly scroll through different sections of the page:

// CONTROL TOP NAVBAR WITH UP/DOWN ON KEYBOARD
        $(document).keydown(function(e) {
          var p = $("li.active");
          if (e.keyCode === 38) {
          e.preventDefault();
          p.prev().find("a").click();
          } else if (e.keyCode === 40) {
          e.preventDefault();
          p.next().find('a').click();
          }
        });

This works fine. However, I also have a contact form on the page. When the user is typing in the contact form, I’d like them to be able to move up/down with their keyboard in the textbox to navigate properly. However, it currently still controls the navbar.

My contact form has the id of #contactform. Code is here:

<form name="contactform" id="contactform" method="post" action="/contact/" _lpchecked="1">
    <ul class="form-block">

      <!-- HONEYPOT -->
      <li class="on-no-robots" style="height:0px; text-indent:-9999px; font-size:0px; overflow:hidden;">
        <label>Humans Don't Submit This!! If you can see this, you don't have CSS, and you scare me. This is just here to filter out automated comments!</label>
        <input name="robotest" id="robotest" type="text" />
      </li>
      <!-- HONEYPOT -->

      <li class="third">
        <label for="name">Name</label>
        <input type="text" name="name" id="name" value="" class="required" />
      </li>
      <li class="third">
        <label for="email">Email Address</label>
        <input type="email" name="email" id="email" value="" class="required email" />
      </li>
      <li class="third">
        <label for="phone">Phone Number</label>
        <input type="text" name="phone" id="phone" value="" />
      </li>
    </ul>
    <h3>How can we help you?</h3>
    <ul class="form-block">
      <li class="full">
        <textarea name="comments" id="comments" class="required"></textarea>
      </li>
      <li>
        <input id="submitButton" type="submit" value="Talk to us" />
      </li>
    </ul>
</form>

Is it possible to make a conditional statement that says “if #contactform#name, #contactform#email, #contactform#comments is in focus, disable this function”?

I’m fairly bad at jquery, but here was my attempt:

        $(document).keydown(function(e) {
            if ($("#contactform input", "#contactform textarea").is(":focus")){
                return;
            }

            else{
              var p = $("li.active");
              if (e.keyCode === 38) {
              e.preventDefault();
              p.prev().find("a").click();
              } else if (e.keyCode === 40) {
              e.preventDefault();
              p.next().find('a').click();
              }
            }       
        });

Currently, the up/down arrow function works fine, although the conditional statment is wrong. What have I missed here?

  • 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-08T12:59:21+00:00Added an answer on June 8, 2026 at 12:59 pm

    Here’s a JavaScript routine (in use on this site) to detect whether a user is in a text field:

    function inTextField(event)
    {
      var elem = event.target || event.srcElement;
      if (elem.nodeType == 3)
        elem = elem.parentNode;
    
      return (elem.tagName == "TEXTAREA" ||
              (elem.tagName == "INPUT" && (elem.getAttribute("type") == "text")));
    }
    

    It could be improved by using jQuery syntax, but even as-is it should be enough to get your conditional working:

    if (inTextField(e)){
        return;
    }
    ...
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

In my site, I have implemented the following functionality: If the user clicks on
I have the following function in a PHP script, which returns and API call:
I have the following factorial function implemented in XSLT: <?xml version=1.0?> <xsl:stylesheet version=1.0 xmlns:xsl=http://www.w3.org/1999/XSL/Transform>
I have the following vexing problem. I have implemented the following function: function bool
I have a WPF application. I have implemented the following function, but no one
I have implemented Ruby C extension(i.e. Invoking C function from ruby script) Following is
I am building a site with vertical scroll. I have implemented the jquery below:
I have following function in one Activity public void AppExit() { Editor edit =
In my MVC application in Controller i have following function to add and focus
have the following function on my collection : getFiltered: function (status, city) { return

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.