-2

I try to get input value of my form. I already try many solutions but still no results. Here is form input:

 <input class="form-control" id="account_ya_price_list_url shop_key_input" name="account[ya_price_list_url]" type="text" style="/* margin-right: 20px; */">

Js:

    console.log($('#shop_key_input').html());
    console.log($('#shop_key_input').val());
    console.log($('#shop_key_input').value);
    var div = document.getElementById('shop_key_input');
    var div2 = document.getElementsByName('account[ya_price_list_url]').first;
    console.log(div2.innerHTML );
    console.log(div.innerHTML );
    console.log(div2.value );
    console.log(div.value );

All of this or undefined or null. What I am doing wrong?

nowiko
  • 2,507
  • 6
  • 38
  • 82
  • 1
    You seem to have confused the `id` and `class` attributes; an `id` (if present) must have only *one* attribute-value (no white-space), and a `class` can take a white-space separated *list* of attribute-values. – David Thomas Dec 08 '14 at 10:42
  • @DavidThomas, you are right – nowiko Dec 08 '14 at 10:45

3 Answers3

4

The value of the id attribute needs to be an id not a space separated list of ids (it does not work like the class attribute).

id="account_ya_price_list_url shop_key_input"

should be

id="shop_key_input"

then #shop_key_input will match it.

Quentin
  • 914,110
  • 126
  • 1,211
  • 1,335
0

Only one ID is allowed per element.

So try using just #shop_key_input and using either document.getElementById('shop_key_input'); or $('#shop_key_input')

Naeem Shaikh
  • 15,331
  • 6
  • 50
  • 88
Peter
  • 330
  • 1
  • 4
  • 18
-2

use class to get the value of textbox

  $('.form-control').val();
I'm Geeker
  • 4,601
  • 5
  • 22
  • 41