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

  • Home
  • SEARCH
  • 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 8250467
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T23:54:02+00:00 2026-06-07T23:54:02+00:00

I am working on a search with JavaScript. I would use a form, but

  • 0

I am working on a search with JavaScript. I would use a form, but it messes up something else on my page. I have this input text field:

<input name="searchTxt" type="text" maxlength="512" id="searchTxt" class="searchField"/>

And this is my JavaScript code:

<script type="text/javascript">
  function searchURL(){
    window.location = "http://www.myurl.com/search/" + (input text value);
  }
</script>

How do I get the value from the text field into JavaScript?

  • 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-07T23:54:04+00:00Added an answer on June 7, 2026 at 11:54 pm

    There are various methods to get an input textbox value directly (without wrapping the input element inside a form element):

    Method 1

    document.getElementById('textbox_id').value to get the value of
    desired box

    For example

    document.getElementById("searchTxt").value;

     
    Note: Method 2,3,4 and 6 returns a collection of elements, so use [whole_number] to get the desired occurrence. For the first element, use [0],
    for the second one use [1], and so on…

    Method 2

    Use
    document.getElementsByClassName('class_name')[whole_number].value which returns a Live HTMLCollection

    For example

    document.getElementsByClassName("searchField")[0].value; if this is the first textbox in your page.

    Method 3

    Use document.getElementsByTagName('tag_name')[whole_number].value which also returns a live HTMLCollection

    For example

    document.getElementsByTagName("input")[0].value;, if this is the first textbox in your page.

    Method 4

    document.getElementsByName('name')[whole_number].value which also >returns a live NodeList

    For example

    document.getElementsByName("searchTxt")[0].value; if this is the first textbox with name ‘searchtext’ in your page.

    Method 5

    Use the powerful document.querySelector('selector').value which uses a CSS selector to select the element

    For example

    • document.querySelector('#searchTxt').value; selected by id
    • document.querySelector('.searchField').value; selected by class
    • document.querySelector('input').value; selected by tagname
    • document.querySelector('[name="searchTxt"]').value; selected by name

    Method 6

    document.querySelectorAll('selector')[whole_number].value which also uses a CSS selector to select elements, but it returns all elements with that selector as a static Nodelist.

    For example

    • document.querySelectorAll('#searchTxt')[0].value; selected by id
    • document.querySelectorAll('.searchField')[0].value; selected by class
    • document.querySelectorAll('input')[0].value; selected by tagname
    • document.querySelectorAll('[name="searchTxt"]')[0].value; selected by name

    Support

    Browser Method1 Method2 Method3 Method4 Method5/6
    IE6 Y(Buggy) N Y Y(Buggy) N
    IE7 Y(Buggy) N Y Y(Buggy) N
    IE8 Y N Y Y(Buggy) Y
    IE9 Y Y Y Y(Buggy) Y
    IE10 Y Y Y Y Y
    FF3.0 Y Y Y Y N
    FF3.5/FF3.6 Y Y Y Y Y
    FF4b1 Y Y Y Y Y
    GC4/GC5 Y Y Y Y Y Y=YES,N=NO
    Safari4/Safari5 Y Y Y Y Y
    Opera10.10/
    Opera10.53/ Y Y Y Y(Buggy) Y
    Opera10.60
    Opera 12 Y Y Y Y Y

    Key:

    IE=Internet Explorer

    FF=Mozilla Firefox

    GC=Google Chrome

    Useful links

    1. To see the support of these methods with all the bugs including more details click here
    2. Difference Between Static collections and Live collections click Here
    3. Difference Between NodeList and HTMLCollection click Here
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a simple search working in my rails app, but it only searches
I have the jstree search plugin working fine inside a HTML page. The data
I have spatial search working well with SOLR 3.2 Example : ?q=*&fq={!geofilt pt=48.86761919303129,2.3527903735351856 sfield=coordinates
I am trying to put full text search working on SQL Server 2008, however
I am altering the question now! I have the search working using the following:
I am working on a search application that uses a form with 16 filter
id like to have an input box that a user can enter a search
This is an odd question. I have a friend who is working on an
I have a script called notify_me.php which I run like so: script type=text/javascript> //Run
I would like to manually apply searching to my jqGrid via JavaScript. I have

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.