Comparing Two Textfield in jquery [closed] - javascript

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 4 years ago.
Improve this question
I have two text fields in my form.
The following are the values of my two text fields
TEXTFIELD1 =
7369:7499:7521:7566:7654:7698:7782:7788:7839:7844:7876:7900:7902:7934
TEXTFIELD2 = 7566
How to check if the value of TEXTFIELD2 does exist in TEXTFIELD1?
Any help would be appreciated. Thank you

You can use string function includes
Assuming the ID of textfields are textfield1 and textfield2, :
var txt1 = $('#textfield1');
var txt2 = $('#textfield2');
if(txt1.val().includes(txt2.val())) {
//action
}

You would want to use Javascript IndexOf. It will return the index of the string found inside the first string. It will return -1 if it is not found. So, you that as the condition to check for the desired string.
let TEXTFIELD1 = "7369:7499:7521:7566:7654:7698:7782:7788:7839:7844:7876:7900:7902:7934"
let TEXTFIELD2 = "7566"
if (TEXTFIELD1.indexOf(TEXTFIELD2) > -1){
console.log("Text Found!");
}
else {
console.log("Text Not Found!");
}

Related

how to prevent user input any string that it's size more than two bytes? (two bytes only) [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 1 year ago.
Improve this question
I'm trying to figure out how to configure my input that only receives two bytes characters. I've tried so many functions here but it seems not to work. For example, I have an input and I want the user just only fill it with 2 bytes characters.
var i = document.createElement("input");
i.type = "text";
document.body.appendChild(i);
i.addEventListener("change", (e) => {
let v = e.target.value;
console.log(v);
let b = (new Blob([v])).size;;
console.log(b);
})

Javascript form validation pattern [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 6 years ago.
Improve this question
I'm trying to validate that two characters and a number were correctly input.
var studentValid = /^[MTWTF][AL][1-9]$/i;
if (studentValid.test(studentTemp.value))
{
alert("true");
}
else
{
alert("false");
}
Yet everything I enter turns out false?
The problem is with your regexp (/^[MTWTF][AL][1-9]$/i). What this tells you is that you first want one of the characters M,T,W,T or F, and after that either A or L and finaly a number (and nothing before or after this).
So for example
ML4, WA5, FL9
will give you true
while
AM9, ML0, MMA5, MA99
will give you false.
Is this the pattern you are trying to match? There is nothing else wrong with your code and a valid value will give you true, for example:
var studentValid = /^[MTWTF][AL][1-9]$/i;
var value = 'MA9';
if (studentValid.test(value))
{
alert("true");
}
else
{
alert("false");
}
When working with regexp, it can be very usefull to use a tool to help you build it, check out https://regex101.com/r/A5FOIh/3 where you can try your different studentTemp.value to see if they match.

How to check each typed word without click btn [closed]

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 7 years ago.
Improve this question
I have a textarea. And foreach word that users type in the textarea i want to check that typed word as they type.
How can i do that best with javascript/angular?
First you'll need an event listener on key presses, if you're using Jquery there's a $.keydown() function, then just listen for space bar presses, something like:
var lastWord = '';
$('textarea').keydown(function(e) {
if (e.keydown == 32) {
//do something with the last word typed
lastWord = ''
} else {
var content = $(this).value
lastWord.concat(content.slice(0,-1)) //last letter in textarea
}
})

ajax get tha value of input type select option [closed]

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
how to get the value of an input select option selected , I have a form with select option. If an option is selected with the value "example_5" I want it to get the value of an selected option
var tow;
var str;
var e = document.getElementById("street");
str= e.value;
Here's the code you need to use:
var e = document.getElementById("street");
var str;
for(var i = 0; i <e.children.length; i++){
var opt = e.children[i];
if (opt.selected == true){
str = opt.value;
}
}

Jquery not disabled the parent [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 7 years ago.
Improve this question
Input tag not disabled.This is my code.Please help me.
var input = $('input[value="' + $(this).val() + '"]');
input.prop('disabled', true);
input.parent('li').addClass('disabled');
You should use filter() to find the input with value instead of using Attribute value selector.
Reduce the set of matched elements to those that match the selector or pass the function's test.
Also you can use closest() to traverse up to desired parent.
Script
var value = $(this).val();
var input = $('input').filter(function(){
return value == $(this).val();
}).prop('disabled', true);
input.closest('li').addClass('disabled');

Categories

Resources