1

i would like to get the value from an input field. The code looks like this:

<input type="number" step="any" 
name="properties[wallpaper_size_width]" class="spb-productdescfont 
spb-productoptiontextcolor spb-productoptionbackground" 
placeholder="Breite in cm" required="">

Because I dont have an id for that input

$("#height").value(); 

will not work. I confused by the [] @name=

How can I select the value by the name?

Kunj
  • 1,980
  • 2
  • 22
  • 34
Fabian Tschullik
  • 95
  • 1
  • 2
  • 9
  • Possible duplicate of [How can I select an element by name with jQuery?](https://stackoverflow.com/questions/1107220/how-can-i-select-an-element-by-name-with-jquery) – CBroe Feb 14 '18 at 11:23
  • try this `$("[name='properties[wallpaper_size_width]']").value(); ` – Ayaz Ali Shah Feb 14 '18 at 11:24

1 Answers1

3

You can use the name selector like this,

$('.getVal').click(function(){
   var value = $("[name='properties[wallpaper_size_width]']").val();
   console.log(value);
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<input type="number" step="any" 
name="properties[wallpaper_size_width]" class="spb-productdescfont 
spb-productoptiontextcolor spb-productoptionbackground" 
placeholder="Breite in cm" required="">

<button class='getVal'>Click me</button>
Ankit Agarwal
  • 30,378
  • 5
  • 37
  • 62