Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 4 years ago.
Improve this question
HTML:
<form id="form_filter" action="{{ Request::fullUrl() }}" method="post">
<input type="checkbox" name="shape[]" value="Aviator">
<input type="checkbox" name="shape[]" value="Round">
<input type="checkbox" name="shape[]" value="Oval">
</form>
I need get element by [name] and [value] as:
$('#form_filter input[name=shape][value=Round]').prop('checked', true);
Please help!
Your have missed [] in the name value, it should be name="shape[]"
$('#form_filter input[name="shape[]"][value=Round]').prop('checked', true);
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<form id="form_filter" action="{{ Request::fullUrl() }}" method="post">
<input type="checkbox" name="shape[]" value="Aviator">
<input type="checkbox" name="shape[]" value="Round">
<input type="checkbox" name="shape[]" value="Oval">
</form>
You should just use quotes inside the selector, ie:
$('#form_filter input[name="shape[]"][value="Round"]').length === 1 // true
Or:
$('#form_filter input[name="shape[]"][value="Round"]').prop('checked', true); // checks your specific checkbox
jQuery docs on equals selector also state the following:
attribute: An attribute name.
value: An attribute value. Can be either a valid identifier or a
quoted string.
Test on the JSFiddle.
Related
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 3 years ago.
Improve this question
Hi there i have a problem and dont know if there's a nice solution to do that.
<input type="checkbox" name="a" value="a">a<br>
<input type="checkbox" name="b" value="b">b<br>
<input type="checkbox" name="c" value="c">c<br>
<input type="checkbox" name="d" value="c">d<br>
<input type="checkbox" name="e" value="c">e<br>
I like to make it work more as a "range" so if a user click "a" and then "d" everything between that will be selected to.
I can make if statements with all the scenarios but maybe there's a better way to do that?
thanks
This is really simple with jQuery - use prevAll like so:
$('input[type="checkbox"]').on("change", function() {
if ($(this).is(":checked")) this.prevAll('input[type="checkbox"]').prop("checked", true);
});
Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 5 years ago.
Improve this question
I'm trying to get value of data-cart-item-id from the input below. But I'm unable to do it.
<td>
<input
id="qinput-xxx"
data-link="http:xxxx"
data-item-id="xxx"
data-cart-item-id="xxxx"
class="qty cart-item-quantity input-text" name=""
value="1"
/>
<button id="qbutton-xxx"
data-item-id="xxx"
disabled="disabled"
data-update
data-cart-item-update
class="button quantity-button">
ok
</button>
</td>
I'm trying with the following code, but I'm getting nothing from it.
document.querySelectorAll('data-cart-item-id')
Since the input has it's own unique id, I would suggest you to use getElementById instead. Then, just get it's data-cart-item-id attribute value with getAttribute function.
var elem = document.getElementById('qinput-xxx'),
data = elem.getAttribute('data-cart-item-id');
console.log(data);
<td>
<input id="qinput-xxx" data-link="http:xxxx" data-item-id="xxx" data-cart-item-id="xxxx" class="qty cart-item-quantity input-text" name="" value="1" />
<button id="qbutton-xxx" data-item-id="xxx" disabled="disabled" data-update data-cart-item-update class="button quantity-button">ok</button>
</td>
data-cart-item-id is not a tag name. It is a property, so use input[data-cart-item-id] or [data-cart-item-id].
Also querySelectorAll retuns an Array of elements, so you have to specify the index.
console.log(document.querySelectorAll('[data-cart-item-id]')[0].getAttribute('data-cart-item-id'));
<td>
<input
id="qinput-xxx"
data-link="http:xxxx"
data-item-id="xxx"
data-cart-item-id="xxxx"
class="qty cart-item-quantity input-text" name=""
value="1"
/>
<button id="qbutton-xxx"
data-item-id="xxx"
disabled="disabled"
data-update
data-cart-item-update
class="button quantity-button">
ok
</button>
</td>
You have to get element by class name for example for
qty class if it is specified for products only then you will get array of products then use a for loop from 0 till element length then with in it use the getAttribute() function you will get that attribute value do your code with it.
Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 7 years ago.
Improve this question
I use this code to make simple form function with javascript, but doesn't work correctly.
(function(){
var o=document.getElementById('formsz');
o.getElementsByTagName('form')[0].onsubmit=function(){
if(this.version.value == "show"){
alert("show")
}else{
alert("hide")
}
return false
}})();
<div id="formz">
<form action='#'>
<input type="radio" name="version" id="x64" value="show">Show<br/>
<input type="radio" name="version" id="x32" value="hide">Hide<br/>
<button type='submit'>Login</button>
</form>
</div>
Whats wrong?? Why it doesn't work ??? Please help,,,
'formzs' !== 'formz' - .getElementById is finding nothing because you've passed the wrong ID in.
Try using your developer console next time, the error is pretty obvious.
(function(){
var o = document.getElementById('formz');
o.getElementsByTagName('form')[0].onsubmit=function(){
if(this.version.value == "show"){
alert("show")
}else{
alert("hide")
}
return false
};
})();
<div id="formz">
<form action='#'>
<input type="radio" name="version" id="x64" value="show">Show<br/>
<input type="radio" name="version" id="x32" value="hide">Hide<br/>
<button type='submit'>Login</button>
</form>
</div>
Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 8 years ago.
Improve this question
I am trying to fetch the value of an input box and displaying that value dynamically using jquery .
The code works fine and loads the image on the check id.
But the value of user_id is not being displayed on <p>
The code is as follows :
<input type="text" autocomplete="off" name="user_id" id="user_id" class="user_name" >
<button>Check</button>
<span class="check" ></span> <br/>
<p> </p>
$(document).ready(function(){
$("button").click(function(){
$('.check').show();
$('.check').fadeIn(400).html('<img src="image/ajax-loader.gif" /> ');
var us=("#user_id").val();
$("p").text(us);
});
});
You missed the $ sing:
$("button").click(function(){
$('.check').show();
$('.check').fadeIn(400).html('<img src="image/ajax-loader.gif" /> ');
var us= $("#user_id").val();
$("p").text(us);
});
Working Example
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
i have a text field , where i input the value to filter ....
<input type="text" name="filter" id="filter">
<input type="radio" name="item" id="item" value="1">apple
<input type="radio" name="item" id="item" value="2">banana
<input type="radio" name="item" id="item" value="3">grapes
<input type="radio" name="item" id="item" value="4">mango
<input type="radio" name="item" id="item" value="5">orange
<input type="radio" name="item" id="item" value="6">pineapple
if i input apple in text field, only radio button with apple has text value should appear , rest must hide . Is der any way to do that ?
Check out the jquery selectors page:
"Attribute Contains Selector [name*="value"]"
var name2lookFor = $('#filter').val();
var $matchingElements = $('input[type="radio"]').filter('[name*="'+name2lookFor +'"]');
There are a lot of other selectors, just find the one you need. You might need a combination to make a bit more custom search, but this should put you in the right track.
Offtopic: An id must be unique, you cant call them the same in the ID attribute.