I have an number input like this:
<input class="easyui-numberbox" data-options="precision:2,required:false" id="price3" name="price3" value="" />
But I can't get the input value with this:
$("input[name=price3]").numberbox('getValue')
But I can get the input value with ID attribute of input:
$("#price3").numberbox('getValue')
Should I define my all inputs an ID attribute to work with EasyUI?
Regards,
You can get an element with a specific attribute value as well. In your example try
$('input[numberboxname="price3"]').val()
Related
Hello I want to change the input type value attribute value when i edit input type.
<input type ="text" id="name" value ="abc">
When I edit the record in input type I want same time value attribute should be change like
suppose I am changing now value abc to xyz the value attribute value
should be value="xyz" how to change or how can I do it on blur.
Add a blur() event something like this. Use browser's inspect element option to view the value attribute of the input text on changing the value to verify the working of the code.
$('#name').blur(function(){
$(this).attr('value', $(this).val());
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<input type ="text" id="name" value ="abc">
A vanilla JS solution:
Add an evenListener for blur and change the value attribute
document.getElementById('name').addEventListener('blur', function() {
this.setAttribute('value', this.value);
console.log(this);
});
<input type ="text" id="name" value ="abc">
i have 2 input of type text (Id and name). I want to search id in my database and find name related to this id and set it in input of name and also disable this input. For this mean i write a function(with java language) that get name related to id input. But i test it with a submit button that is not what i want.1) I want to call function when id input is fill
2)also the name input disable option set to true, when id input is empty it change to false
This is my jsp code:
<input type="text" id="id">
<input type="text" id="name">
<input type="submit" formaction="myFunc">
You should use onChange event, that is described here: https://www.w3schools.com/jsref/event_onchange.asp
As #Marek said, use the onchange event to call a JavaScript function. Then see this post for how to disable an input with JavaScript:
How to disable an input type=text?
Lets say I have a form with multiple fields like this :
<form>
<input type="checkbox" name="title45" value="title45"><input type="text" name="title45" /><br>
<input type="checkbox" name="title45" value="title45"><input type="text" name="title23" /><br>
<input type="checkbox" name="title45" value="title45"><input type="text" name="title36" />
</form>
Like this, there can be up-to 100 text fields. I need a way to select several or all of them and set the value once and the selected elements will get the value. How can I do this?
I will add a checkbox infront of the fields. I want to edit only the checked ones.
just this line of jquery :
$('form input').val("fgg");
see this in action: http://jsfiddle.net/c53nqn7e/
You get/set input values with .val(). So:
$('input').val('something')
You can narrow down the inputs selected in a variety of ways, like:
$('input[type="text"]').val('something') // select all text inputs
$('input[name^="title"]').val('something') // select all inputs with a name attribute that starts with title
you can do it like this:
$( ":input" ).val("your input value");
or
$( "form input" ).val("your input value");//better because it will apply only on form
but i'll suggest add class to these inputs and based on class assign the values so you can have some discrimination.
The elements & the code.
HTML
<input value="" name="data[Filter][address]" type="text" />
<input value="" name="data[Filter][client]" type="text" />
<input value="" name="data[Filter][tenant]" type="text" />
<input value="" name="data[Filter][contract_end_date]" type="text" />
Javascript
console.log($("[name*='data\\[Filter\\]'][value!='']").serialize());
The problem: even if they are all empty, they are serialized.
Why?
You're looking at the value attribute. You can filter off of the value property instead:
http://jsfiddle.net/Y2P6w/
var $filledElems = $("[name*='data\\[Filter\\]']").filter(function () {
return $.trim(this.value).length;
});
The point is when the input tag gets inserted to the page, no matter it is in the page load or in your dynamic JavaScript codes, if it has the value attribute your selector query would use it or if you change your input's value using setAttribute in JavaScript or .attr() in jQuery, their value attribute actually gets changed, but if you change it with .value in JavaScript or .val() in jQuery or simply change the value in the page as a textbox, the attribute won't change, so you better not use value attributes in your selectors, because they are not reliable, an instead use $("[name*='data\\[Filter\\]']") and filter it as #JasonP has pointed out.
I have several input elements, that only differ on their data- attribute.
<input name="country" data-action="buy"/>
<input name="country" data-action="sell"/>
I'm trying to get the value that the user entered into the input with a "buy" data-
What's the selector I should use?
$("input[name=country] ????").val()
(There is a reason they have the same name and no id that's not related to the question)
Just add data-action="buy" also as an attribute selector
$('input[name="country"][data-action="buy"]').val()
$("input[data-action='buy']").val()
$("input[name='country']").filter(i) {
return $(this).data('action') == 'buy';
}).val();