How to make an input for key verify with any prefix? - javascript

So I tried to make a key input that when users write something, prefix to be geton_ and random characters next... For example: geton_adminloginpanel or geton_lgpanel.
Tried this but not work like I thought:
HTML:
<!DOCTYPE html>
<html>
<head>
<title>KeyPanel</title>
</head>
<body>
<span>Enter The Key</span>
<input aria-label="Enter the key" id="key-text" placeholder="Key" value="">
<button role="button" value="submit" id="key-btn" onclick="fctbtnkeygetorerror()">LOGIN</button>
</body>
</html>
JAVASCRIPT:
<script>
function fctbtnkeygetorerror() {
if (document.getElemetById("key-text").value == "geton_" + document.getElemetById("key-text").value) {
alert("Successfully Logged In");
} else {
alert("Invalid Key");
}
}
</script>

<script>
function fctbtnkeygetorerror() {
main_password = "geton_Password";
prefix = "geton_";
input_value = document.getElementById("key-text").value;
new_value = prefix+input_value;
if(new_value==main_password){
alert("Login Success");
}else
{
alert("Invalid Login");
}
}
</script>

Related

Cheker to clean a string

I'm doing a small script with jquery, I'd like, that by clicking on the checkbox, I'll take the first textarea and pass it to the 2 text area without numbers, but, that textarea 1 will be as it is in 2
$(document).ready(function() {
function validate() {
if (document.getElementById('cheker').checked) {
results = document.getElementById("all").value;
final = results.string.replace(/\d+/g, '');
document.getElementById("filtrado").value(final);
} else {
}
}
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<textarea id="all"></textarea>
<input id="checker" name="checker1" type="checkbox" />
<textarea id="filtrado"></textarea>
"value" is a property , as mentioned by jonas and you have a wrong in id "cheker > checker" , try this
$(document).ready(function() {
function validate() {
if (document.getElementById('checker').checked) {
results = document.getElementById("all").value;
final = results.replace(/\d+/g, '');
document.getElementById("filtrado").value = final;
} else {
}
}
});
No need to call string on a variable that is already a string, that and some typos and LGSon's comment, try this
<!DOCTYPE html>
<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script>
$(document).ready(function() {
function validate() {
if (document.getElementById('checker').checked) {
results = document.getElementById("all").value;
final = results.replace(/\d+/g, '');
document.getElementById("filtrado").value=final;
} else {
}
}
$('#checker').change(function(){
validate()
});
});
</script>
</head>
<body>
<textarea id="all"></textarea>
<input id="checker" name="checker1" type="checkbox" />
<textarea id="filtrado"></textarea>
</body>
</html>

Why can't I display alert if text box has a value?

I'm trying to get a function to run an if statement only if something has no value.
<script src="https://jqueryvalidation.org/files/lib/jquery-1.11.1.js"></script>
<script type="text/javascript">
function checkNSC() {
var confirmNSC = $("#SelectNsc");
if (confirmNSC.length == 0) {
alert("Please ensure all required fields are filled out")
}
else {
alert("NSC has value")
}
}
</script>
HTML:
<input type="text" id="SelectNsc" />
<button onclick="checkNSC();" id="myButton">My Button</button>
</div>
I'm trying to say if the value is 0 then to display an alert saying (Please ensure all fields are filled out". Otherwise say "NSC has a value"
Thanks,
Should be,
var confirmNSC = $("#SelectNsc").val();
Because $("#SelectNsc") return a jquery object, so that $("#SelectNsc").length will always return a value greater than 0.
<script src = "https://jqueryvalidation.org/files/lib/jquery-1.11.1.js" > < /script>
<script type = "text/javascript" >
$(document).ready(function() {
$("#myButton").click(function() {
var confirmNSC = $("#SelectNsc").val().trim();
if (confirmNSC.length == 0) {
alert("Please ensure all required fields are filled out")
} else {
alert("NSC has value")
}
});
})
</script>
Fiddle
Try this, It's working fine
<script src="https://jqueryvalidation.org/files/lib/jquery-1.11.1.js"></script>
<script type="text/javascript">
function checkNSC() {
var confirmNSC = $("#SelectNsc");
if (confirmNSC.val() =='') {
alert("Please ensure all required fields are filled out")
}
else {
alert("NSC has value")
}
}
</script>
<input type="text" id="SelectNsc" />
<button onclick="checkNSC();" id="myButton">My Button</button>
</div>
use this code :
<body>
<script src="https://jqueryvalidation.org/files/lib/jquery-1.11.1.js"></script>
<script type="text/javascript">
function checkNSC() {
var confirmNSC = document.getElementById("SelectNsc").value;
if (confirmNSC.length == 0) {
alert("Please ensure all required fields are filled out")
}
else {
alert("NSC has value")
}
}
</script>
<input type="text" id="SelectNsc" />
<button onclick="checkNSC();" id="myButton">My Button</button>
</body>
OR , use this code :
<body>
<script src="https://jqueryvalidation.org/files/lib/jquery-1.11.1.js"></script>
<script type="text/javascript">
function checkNSC() {
var confirmNSC = $("#SelectNsc").val();
if (confirmNSC.length == 0) {
alert("Please ensure all required fields are filled out")
}
else {
alert("NSC has value")
}
}
</script>
<input type="text" id="SelectNsc" />
<button onclick="checkNSC();" id="myButton">My Button</button>
</body>

Detect if a textbox does not contain certain words

I want to know how to detect if a textbox does not contain certain words. For example if the textbox did not contain 'who', 'what', 'why', 'when' or 'where' some sort of function would run.
JavaScript:
function command() {
var srchVar = document.getElementById("srch");
var srch = srchVar.value;
var t = srch;
if (srch == '') {
alert('Please do not leave the field empty!');
}
else if (srch.indexOf('time') != -1) {
alert('The current time according to your computer is' + ShowTime(new Date()));
}
else if (srch.indexOf('old are you') != -1) {
alert("I am as old as you want me to be.");
}
else {
if (confirm('I am sorry but I do not understand that command. Would you like to search Google for that command?') == true) {
window.open('https://google.co.uk/#q=' + srch, '_blank');
}
else { /* Nothing */ }
}
}
HTML:
<!DOCTYPE html>
<html>
<head>
<script src="script.js" type="text/javascript"></script>
<link href="http://code.jquery.com/ui/1.10.4/themes/ui-lightness/jquery-ui.css" rel="stylesheet">
<script src="http://code.jquery.com/jquery-1.10.2.js"></script>
<script src="http://code.jquery.com/ui/1.10.4/jquery-ui.js"></script>
</head>
<body>
<div class="ui-widget">
<input class="search-field" id="srch" onkeypress="searchKeyPress(event);" placeholder="ask me anything" spellcheck="false">
</div>
</body>
</html>
You will want to call that function when you press a button.
Try something in your HTML like:
<input class="info" onclick="contains();" type="button">
And in your JS
function contains() {
var srchVar = document.getElementById("srch");
var srch = srchVar.value;
if (
(srch.indexOf('who')==-1) &&
(srch.indexOf('what')==-1) &&
(srch.indexOf('why')==-1) &&
(srch.indexOf('when')==-1) &&
(srch.indexOf('where')==-1)
) {
alert("That is not a question");
}
}
You will want to merge this with your command() function in the future.
Also, what does info(); do ?

password validation not working for me

i need to make an html page when you put a password to. whenever the user insert the correct password he will be sent out to a website. if the user won't insert the correct password he will get a an error.(i need to do it with only javaScript.no jquery and stuff like that) this is what i did -
<form>
Write the password here:
<input type="text" id="putPass" name="go2" /> <br />
<input type="button" value="click here" id="press" onclick="pass()" />
</form>
<script type="text/javascript">
var password = ["1234","abcd","0000","1111","4321"]
function pass()
document.getElementById("putPass").value. //it says it has a syntax error and i dont know why...
if (this == password[])
{
document.write("good job!");
}
else
{
alert("try again!");
}
</script>
thank you.
You can try to do that using this code.
http://jsfiddle.net/VAK3N/
<form>
<input type="text" id="putPass" name="go2" />
<br />
<input type="button" value="click here" id="press" />
</form>
<script type="text/javascript">
var password = ["1234", "abcd", "0000", "1111", "4321"];
document.getElementById('press').onclick = function () {
var p = document.getElementById("putPass").value;
if (password.indexOf(p) > -1) {
alert("good job!");
} else {
alert("try again!");
}
}
</script>
Try this
<script type="text/javascript">
var password = ["1234","abcd","0000","1111","4321"];
function pass(){
var userPass = document.getElementById("putPass").value;
if (in_array(userPass, password)){
document.write("good job!");
}
else {
alert("try again!");
}
}
function in_array(needle, haystack){
for(var key in haystack)
{
if(needle === haystack[key])
{
return true;
}
}
return false;
}
</script>
var pass = document.getElementById("putPass").value;
var correct = false;
for (var i=0;i<password[].length;i++){
if (password[i] == pass){
correct = true;
break;
}
}
if (correct){
document.write("good job!");
} else {
alert("try again!");
}
Not sure if that exact code will work, but I think that you need to check each password individually in a for loop, you can't compare strings with entire arrays.
I didn't see first that you dont want to use jQuery. So then here is the working code for you.
JS:
var password = ["1234","abcd","0000","1111","4321"]
function pass(){
var input = document.getElementById('putPass').value;
var accepted= false;
for(var pass in password){
if(password[pass] == input ){
accepted= true;
}
}
if(accepted){
alert('good job!');
}else{
alert('try again!');
}
}
HTML:
<form>
<input type="text" id="putPass" name="go2" /> <br />
<input type="button" value="click here" onClick="pass();" id="passSender"/>
</form>

Check Passwords Match Issue (JavaScript)

can anybody see the issue with the following code? My script continues, ignoring my check.
The code below is only a snippet of the code but this issue is in here somewhere after doing some debugging.
function validatePasswordMatch(string1, string2) {
if (string1 != string2) {
return false;
} else {
return true;
}
}
var validatePasswordMatchFields = ["textbox2", "textbox3"];
if (validatePasswordMatch($("#" + validatePasswordMatchFields[0]).val(), $("#" + validatePasswordMatchFields[1]).val())) {
(some code)
} else {
return false;
}
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>stackoverflow</title>
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script>
<script>
$(document).ready(function(){
function validatePasswordMatch(string1, string2) {
if (string1 !== string2) {
return false;
} else {
return true;
}
}
var validatePasswordMatchFields = ["textbox2", "textbox3"];
$(document).on('click','button',function(){
result = validatePasswordMatch($("#" + validatePasswordMatchFields[0]).val(), $("#" + validatePasswordMatchFields[1]).val())
if (result) {
alert("match")
} else {
alert("not match")
}
})
});
</script>
</head>
<body>
<input id="textbox2" type="text" placeholder="password">
<input id="textbox3" type="text" placeholder="password">
<button type="button" id="button">Click Me!</button>
</html>

Categories