0
How to change upper case to lower and lower case to upper using if else with jQuery input type with id txt?
$("btn").on("click", function (){ $("txt1").Val(function (i,val) { return val.toUpperCase(); }); }); How to add if condition for checking it uppercase and lower case of Val in input type with id txt1
7 Antworten
+ 1
This is what it does if you use function inside, it modify selected element, so if this is what you need, you can choose this way.
But if you need to take input value, store it and send to server, than you use method without function inside
https://api.jquery.com/val/#val-function
https://code.sololearn.com/WvMS6A5aJTVD/?ref=app
+ 1
Please show your code first
+ 1
To select element by id you need to add # in selector part, if you use val without function it will return just value of input and store on some variable
https://code.sololearn.com/WdOAI22qW3ok/?ref=app
+ 1
$("#btnRev").click(function(){
let r="", t = $("#txt").val();
for (i=0; i<t.length; i++) {
if (t[i] == t[i].toUpperCase())
r += t[i].toLowerCase();
else
r += t[i].toUpperCase();
}
$("#lbl").text(r);
});
// I hope this code helps you.
https://code.sololearn.com/WzTxUYDagkSA
0
Compare is val is same as val.toUpperCase() if is than it was uppercase and you turn it to lower and vice versa.
0
$("btn").on("click", function (){
$("txt1").Val(function (i,val) {
If($(this).val===$(this).val.toLowerCase()){
return val.toUpperCase();
} else {
return val.toLowerCase();
}
});
});
Like this but it isn't working.
0
This is how you take value of input
https://www.tutorialrepublic.com/faq/how-to-get-the-value-in-an-input-text-box-using-jquery.php