Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Closed 8 years ago.
This question appears to be off-topic because it lacks sufficient information to diagnose the problem. Describe your problem in more detail or include a minimal example in the question itself.
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
Improve this question
Trying to add a second condition to a js function
original condition
if (content.length==elmnt.maxLength)
new condition
if (content.length==elmnt.maxLength && current form field value > 1400)
how do I code "current form field value > 1400" properly in javascript?
Full original code:
<SCRIPT TYPE="text/javascript">
function jumpField(elmnt,content)
{
if (content.length==elmnt.maxLength)
{
next=elmnt.tabIndex
if (next<document.forms[0].elements.length)
{
document.forms[0].elements[next].focus()
}
}
}
</SCRIPT>
Thanks!
Not sure if I fully understand what you are trying to achieve.
Are you looking for parseInt() to convert a string value? Like:
parseInt(document.forms[0].elements[next].value) > 1400
Related
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question appears to be off-topic because it lacks sufficient information to diagnose the problem. Describe your problem in more detail or include a minimal example in the question itself.
Closed 8 years ago.
Improve this question
Can someone please tell me how to compare elements in array with every other element. I mean in array arr = [a,b,c,d];, I would like to compare a with b,c,d , b with a,c,d, etc. And to do that dynamically, no mather of the size of the array.
Try this:
var a=["a","b","c","d"];
for(var i=0;i<a.length;i++){
for(var j=0;j<a.length;j++){
if(i!=j && a[j]===a[i]){
//match, do whatever you want
}
}
}
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Closed 8 years ago.
This question appears to be off-topic because it lacks sufficient information to diagnose the problem. Describe your problem in more detail or include a minimal example in the question itself.
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
Improve this question
I have an object in Angular looking like this:
$scope.addEmployeeDepartments={ 5066549580791808=true, 6192449487634432=true, 7192449487634432=false}
How do I generate a comma-separated string like this
var ids="5066549580791808, 6192449487634432"
containing all the keys which are true ?
Btw, I am using underscore.js in other parts of my solution, so I don't know if that makes it easier.
thanks
Thomas
You can do this with reduce in one pass:
var collect_trues_in = function(a, v, k) {
if(v)
a.push(k);
return a;
};
var csv = _($scope.addEmployeeDepartments).reduce(collect_trues_in, [ ]).join(', ');
Demo: http://jsfiddle.net/ambiguous/6CEZW/
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Closed 8 years ago.
This question appears to be off-topic because it lacks sufficient information to diagnose the problem. Describe your problem in more detail or include a minimal example in the question itself.
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
Improve this question
is it possible to convert a text from an input to a string or integer?
I have an input field, in which you can search a company:
<input type="text" id="company" name="company" />
Now I need the value as a string or int.
Thanks for you help.
Value of the input field is a string by default. You can convert it to an int by
parseInt(document.getElementById("company").value,10);
It is Simple stuff. You can convert by using parseInt() Function.
It will convert your string to Integer.
function convert()
{
var x=document.getElemenyById("company").value;
x=parseInt(x);
}
jquery version:
parseInt($( "#company" ).val(), 10);
plain javascript:
parseIntdocument.getElementById('company').value, 10);
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 am new to jQuery. I have a text field and I want to validate this field so that it only takes character and alphanumeric values, however if you put in a numeric value it will show a message. How should I implement this?
$('#textfieldid').on('change', function(event) {
var text = $('#textfieldid').text();
//some validation code here
});
By the way, JQuery is a javascript library, not Java (which you have tagged).
Using regex, validations can be done.
var password = document.getElementB;
var letter = /[a-zA-Z]/;
var number = /[0-9]/;
if(number.test(password) && letter.test(password)){
//success
}else{
//error
}
Here password is the value which is returned from the field
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 this issue when im trying to upload a form in ie: Object doesn't support property or method 'ajaxSubmit' Here is my code:
function Upload() {
ShowWait();
uploadCompleted = false;
$(document.forms[0]).ajaxSubmit({ success: PostUploadProcess });
intervalHandler = setInterval(function () {
var responseText = $("iframe").contents().find("body").html();
if (responseText)
PostUploadProcess(responseText);
}, 1000);
return false;
}
Can anyone help me?
http://malsup.com/jquery/form/
needs to be separately included. its not part of jquery core.