get input value using data-attribute with jquery

Carlitos Overflow

How can i get the input value using data-attributes with jQuery? This is my function which is not working. the return value of valuefromscenariotwo should be "My test 2"

var valuefromscenariotwo = getvaluefromScenariotwo("scenario2");
function getvaluefromScenariotwo(name){
  return $(input[data-scenario=name]).val();
}

<div class="form-group">
<input type="text" data-scenario="scenario1" class="form-control notes" placeholder="Enter Notes"           value="My test 1">
</div>;
<div class="form-group">
<input type="text" data-scenario="scenario2" class="form-control notes" placeholder="Enter Notes"   value="My test 2">
</div>;
<div class="form-group">
<input type="text" data-scenario="scenario3" class="form-control notes" placeholder="Enter Notes"   value="My test 3">
</div>;
adeneo

You need to add some quotes and concatenation to that

function getvaluefromScenariotwo(name){
    return $('input[data-scenario="' + name + '"]').val();
}

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

How to get the value of data attribute using jquery

Unable to get value of data attribute using jQuery

How to get data attribute value using jquery

How to get value and data attribute form input using jQuery .map function

getting input dropdown text value based on data attribute using jquery

How to get the input value using data attribute inside a tbody?

jQuery Get Value of data Attribute

Get correct data attribute for the matched value using jquery

Get value of data attribute using jQuery in parent element

Unable to get data attribute value in jquery using PHP

Get data attribute value of the Nth element using jQuery

Get value of data attribute of <li> element using jQuery

Find value of input, by known data attribute? - jQuery

How to get data-value from radio input using jquery?

get value based on id and data attribute jquery

how to get value of data attribute and use it in jquery?

get data-attribute value in jquery

Jquery - Get Data attribute text value

How to get a value of data-attribute with jquery

Get value of a Custom Attribute using Javascript or Jquery

Not able to get the value of xml attribute using jquery

How to get to attribute value using jquery

How to access the value of a data attribute using jQuery

Using jQuery to get data attribute values with .each()

Change the value of span using Javascript or Jquery using <input> or text attribute

How to get the value of input field by custom attribute in jquery

Check if "data" attribute contains A PART of input value (jQuery)

How to get the value of data attribute using JQuery in asp.net core?

Get attribute value with jQuery