my question is that i know that chrome browser cant execute common js modules but in the node js file it is importing everything as common js and chrome is showing error and if i use ecmascript(e26)module to import nodemailer then it says cant import a module outsde a statement so their are two errors how to solve them or my technique is wrong to insert the nodemailer plz help me with it and thaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaanks in advance
here is my code
import * as nodemailer from "nodemailer"
var a=Math.round(Math.random()*999999);
c=document.getElementById("p");
var b=c;
function otpch(){
if(document.getElementById("optcheck").value===a){
document.open();
document.write("You are successfully Logged In")
}
}
function otpm(){
alert(4236)
var mailOptions = {
from: 'mygmailid#gmail.com',
to: b,
subject: 'Your Otp',
text: 'Your onetime otp is'+a
};
alert(4236)
var transport = nodemailer.createTransport({
service: 'gmail.com',
auth: {
user:'friendsgmailid#gmail.com',
pass:'itssecret'
}
});
alert("hi123");
transport.sendMail(mailOptions,function(err,info){
if(err) {
document.getElementById("demo").innerHTML="Error while sending otp please check your gmail id which you filled is correct or not ";
} if(info){
document.getElementById("demo").innerHTML="Otp Sent Successfully";
}
});
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<script type="module" src="nodemailer/lib/nodemailer.js"></script>
<script src="sketch.js"></script>
</head>
<body >
<h3>Welcome to our site jain services</h3>
<h5>Write Your Gmail Address</h5>
<p id="p"><input id="gmailcheck"type="email" placeholder="Write Your Gmail" required></p>
<h4>click on the button to sign in</h4>
<button onclick="otpm()" type="submit"id="un" style="border: 3px solid black; border-radius: 50px;">Submit</button>
<h3 id="demo" style="color: red;">.</h3>
<input id="otpcheck" onclick="otpch()" type="number">
</body>
</html>
Related
have created a Web Form to upload data(Rich Text) to Firebase Database,
But sometimes data is entered to Database and other Times the Fields in the Database is completely Empty. Can Anyone suggest me the solution as I am new to Web Dev.
Here is my WebForm Code (Rich Text is only in Description):
<script>
CKEDITOR.replace( 'quote' );
// Initialize Firebase
var database = firebase.database();
var quote;
function getdata(){
quote = document.getElementById('quote').value;
}
document.getElementById('submit').onclick = function(){
getdata();
firebase.database().ref("quoteday/quotes").set({
Data: quote,
})
}
document.getElementById('delete').onclick = function(){
firebase.database().ref("quoteday/").remove();
}
</script>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<!----======== CSS ======== -->
<link rel="stylesheet" href="style.css">
<script src="//cdn.ckeditor.com/4.17.2/full/ckeditor.js"></script>
</head>
<body>
<div class="form-group">
<label for="title">Quote day</label>
<textarea class="form-control" id="quote" name="quote" rows="3"
data-form-field="Message" placeholder="" autofocus=""
style="display: none;"></textarea>
</div>
<div><button id="submit">Submit/Update</button></div>
<div><button id="delete">Delete</button></div>
</body>
</html>
enter image description here
Because your textarea is empty, you have to type CKEDITOR.instances.quote.updateElement(); before get element value
Updates the element that was replaced by the editor with the > current data available in the editor.
Note: This method will only affect those editor instances created with the CKEDITOR.ELEMENT_MODE_REPLACE element mode or inline instances bound to
elements.
function getdata(){
CKEDITOR.instances.quote.updateElement();
quote = document.getElementById('quote').value;
}
If it still doesn't work, you can test this block as below
firebase.database().ref("quoteday/quotes").set({
Data: 'Test Data',
})
and then check your database, if Test Data saved or not ?
I've been experimenting with a local sign in/log in system and I've hit a error. I was trying to make a regular expression that checks if the user's username and password contain 8 characters and 2 numbers. I really am not sure how to do that but this is all my code I've been able too put togheter.
HTML code:
<!DOCTYPE html>
<meta content="text/html;charset=utf-8" http-equiv="Content-Type">
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
</head>
<body>
<form id='form'>
<title>Sign Up #1</title>
<h3>Simple Signup system</h3>
<div>
<label>Username:</label>
<input type="text" name="text1" id = "username">
</div>
<div>
<label>Password:</label>
<input type="text" name="text2" id = "password">
<div>
<button type="button" id="subBtn">Sign Up!</button>
</form>
</body>
<script src="main.js"></script>
</html>
My JS code:
var t = 'everything good, loging in'
var f = 'something is not right, try again.'
var tf = 'not-set'
var statment = /^[a-zA-Z]*$/
window.onload = function() {
document.getElementById('subBtn').addEventListener('click', onSubmit);
}
// main
function onSubmit() {
if (document.getElementById('username').value.includes(Number)) {
tf = 'True'
} else {
tf = 'False'
}
if (document.getElementById('username').value.includes(statment)) {
tf.push('True')
} else {
tf.push('False')
}
if (tf = ['True', 'True']) {
alert('Good to go, redirecting')
} else {
alert('Username does not meet the standards for creating a account!')
}
document.forms['forms1'].submit()
}
EDIT: Was able to redo a part of the code, I'm still using regex to check for letters because I'm not sure how to do it without it.
Current error: 'first can't be a Regular Expression'.
In my electron app I have a function to clear my input fields on a button press, but after using it I can't click and type into inputs anymore. However, if I open up the inspector window, they work again.
Why does this happen and how do I fix it?
Electron app's main.js:
const { app, BrowserWindow, Menu } = require('electron');
let win;
function createWindow() {
win = new BrowserWindow();
win.loadFile('window_main/index.html');
}
app.on('ready', createWindow);
index.html
<body>
<input type="text" id="testinput" />
<button id="clear">Clear</button>
<script src="index.js" type="text/javascript"></script>
</body>
The problematic bit of JS in index.js:
document.getElementById('clear').addEventListener("click", clear);
function clear() {
if (confirm("Clear all inputs?")) {
document.querySelectorAll('input').forEach((input) => {
input.value = '';
})
}
}
I reproduced your code after removing the script which is not explained why you are using it, anyhow below is a code using jQuery does the trick, this should get you to the right place at least.. if still didn't work with you post a better explanation of your code for a better help...
mark it as answered if it solves your problem....
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script>
<title>Document</title>
</head>
<body>
<input type="text" id="testinput" />
<button id="clear">Clear</button>
<script>
$(document).ready(()=>{
document.getElementById('clear').addEventListener("click", clear);
})
function clear() {
if (confirm("Clear all inputs?")) {
document.querySelectorAll('input').forEach((input) => {
$(input).val('');
})
}
}
</script>
</body>
</html>
The problem was not clearing the inputs, but rather showing the confirm box. I used the following snippet instead:
dialog.showMessageBoxSync(
title: "Clear inputs",
message: "Clear all input boxes?",
type: "warning",
buttons: ["Cancel", "Ok"]
})
And now everything works as expected.
function getDogImage(breed) {
fetch(`https://dog.ceo/api/breed/${breed}/images/random`)
.then(response => response.json())
.then(responseJson =>
displayResults(responseJson))
.catch(error => alert('Something went wrong. Try again later.'));
}
function displayResults(responseJson) {
console.log(responseJson);
//replace the existing image with the new one
$('.results-img').replaceWith(
`<img src="${responseJson.message}" class="results-img">`
)
//display the results section
$('.results').removeClass('hidden');
}
function watchForm() {
$('form').submit(event => {
event.preventDefault();
getDogImage($('#breed').val());
});
}
$(function() {
console.log('App loaded! Waiting for submit!');
watchForm();
});
* {
box-sizing: border-box;
}
body {
font-family: 'Roboto', sans-serif;
}
.container {
max-width: 600px;
margin: 0 auto;
}
.hidden {
display: none;
}
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Dog API Example</title>
<link rel="shortcut icon" href="">
<link rel="stylesheet" href="index.css">
</head>
<body>
<div class="container">
<h1>Dog API: A Simple Example</h1>
<form>
<label for="breed">Breed</label>
<input type="search" name="phone" id="breed" placeholder="Enter Breed" title="dog breeds" required/>
<input type="submit" value="Get a dog pic!">
</form>
<section class="results hidden">
<h2>Look at this dog!</h2>
<img class="results-img" alt="placeholder">
</section>
</div>
<script src="https://code.jquery.com/jquery-3.3.1.js" integrity="sha256-2Kok7MbOyxpgUVvAk/HJ2jigOSYS2auK4Pfzbm7uH60=" crossorigin="anonymous"></script>
<script src="index.js"></script>
</body>
</html>
How do I get an alert or error message to display in my app if the api is unable to locate the breed name passed in by the user. At the moment a broken image link is displayed when passing in a non-valid breed name. Also im new to programming just here trying to learn from experienced developers
Heres a link to my code
https://repl.it/#Mike65/get-fetch-dog-api-example-DOM-3
img tag has onerror event, you can call alert function on that event like this
HTML
<img src=`${response.message}` class='result-img' onerror="myAlert()" />
Javascript
function myAlert() { alert("the image could not load"); }
JQuery
$('.results-img').replaceWith(
`<img src="${responseJson.message}" class="results-img">`
).on("error", function() { alert("the image could not load"); }
I'm trying to set up the DirectLineJS to work in a website just for testing purposes right now. I've built the DirectLineJS repo and added /built/directLine.js to my website folder following the documentation here https://github.com/Microsoft/BotFramework-DirectLineJS
In the HTML page I'm just using a button to try to send a message through the direct line
<html>
<head>
<meta charset="UTF-8" />
<title>Bot Chat</title>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
<script src="http://unpkg.com/botframework-directlinejs/directLine.js" type="javascript"></script>
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no" />
<style>
.wc-chatview-panel {
width: 320px;
height: 500px;
position: relative;
}
.h2 {
font-family: Segoe UI;
}
</style>
</head>
<body>
<h2 style="font-family:Segoe UI;">Welcome to my custom Bot!</h2>
<section class="container">
<input id="clickMe" type="button" value="clickme" onclick="connectDirectLine();" />
</section>
<textarea id="myTextarea">
342 Alvin Road
Ducksburg</textarea>
<p>Click the button to change the contents of the text area.</p>
<button type="button" onclick="myFunction()">Try it</button>
<script>
function myFunction() {
var text = document.getElementById("myTextarea").value;
console.log(text)
}
</script></body>
</html>
<script>
function connectDirectLine() {
import { DirectLine } from 'botframework-directlinejs';
var directLine = new DirectLine({
secret: "mySecret",
});
directLine.postActivity({
from: { id: 'myUserId', name: 'myUserName' }, // required (from.name is optional)
type: 'message',
text: 'a message for you, Rudy'
}).subscribe(
id => console.log("Posted activity, assigned ID ", id),
error => console.log("Error posting activity", error)
);
directLine.activity$
.filter(activity => activity.type === 'message' && activity.from.id === 'yourBotHandle')
.subscribe(
message => console.log("received message ", message)
);
}
</script>
<html
When I run the website the error I'm getting is unexpected token import from import { DirectLine } from "botframework-directlinejs";
how can I properly import the botframework-directlinejs file so that I can use the DirectLine object?
You are mixing TypeScript with JavaScript.
To use Direct Line add the following to the HTML of your page:
<script src="http://unpkg.com/botframework-directlinejs/directLine.js"/>
Then you should delete your Import statement and finally, update the code that creates the DirectLine object to be:
var directLine = new DirectLine.DirectLine({
secret: "mySecret",
});
Notice the DirectLine.DirectLine