Qr Code generator doesn't replace old qr code - javascript

Hello!
I have the following problem.
I have programmed a Qr Code generator.
Now when I click on the Button "Click Me!" a new QR-Code should be generated and replace the old one.
Unfortunately it doesn't replace the old Qrcode but puts the new one under it.
here is my HTML and JS
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width,
initialscale=1">
</head>
<body>
<select name= "Bauart" id= "qr-data">
<option value="1">test</option>
<option value="ad">test 2</option>
</select>
<button onclick="myFunction()">Click me</button>
<div id="qrcode"></div>
<br>
</body>
<script src="qrcode.min.js"></script>
<script src="javascript.js"></script>
</html>
and here is the JS
function myFunction() {
var qrdata = document.getElementById('qr-data').value;
var qrcode = new QRCode(document.getElementById('qrcode'));
qrcode.makeCode(qrdata);
}

<style>
/* CSS comes here */
body {
padding:20px;
}
input {
padding:5px;
background-color:transparent;
border:none;
border-bottom:solid 4px #8c52ff;
width:250px;
font-size:16px;
}
.qr-btn {
background-color:#8c52ff;
padding:8px;
color:white;
cursor:pointer;
}
</style>
<h3>QR Code Generator</h3>
<div><input id="qr-text" type="text" placeholder="Text to generate QR code"></div>
<br>
<div>
<button class="qr-btn" onclick="generateQRCode()">Create QR Code</button>
</div>
<br>
<p id="qr-result">This is deault QR code:</p>
<canvas id="qr-code"></canvas>
<script src="https://cdnjs.cloudflare.com/ajax/libs/qrious/4.0.2/qrious.min.js"></script>
<script>
/* JS comes here */
var qr;
(function() {
qr = new QRious({
element: document.getElementById('qr-code'),
size: 200,
value: 'https://setools.xyz'
});
})();
function generateQRCode() {
var qrtext = document.getElementById("qr-text").value;
document.getElementById("qr-result").innerHTML = "QR code for " + qrtext +":";
alert(qrtext);
qr.set({
foreground: 'black',
size: 200,
value: qrtext
});
}
</script>
Here is the full set of code

Related

Show Captured WebCam file name to Next Page in Python (Flask)

I am trying to capture an image from WebCam and show its file name on the next page when the user clicks the Upload button.
Currently, the snap function is taking the image and working fine. But When the users click on the Upload button, nothing happened.
Expected Output: Click on the Upload button will open a New Page (Test2) and show the file name.
My Code
app.py
#app.route('/Test', methods=['GET','POST'])
def Test():
if request.method == 'POST':
return render_template('Test2.html',data=request.form['file'])
return render_template('Test.html')
if __name__ == '__main__':
app.run(debug=True)
Test.html
<!doctype html>
<html lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>WebcamJS Test Page</title>
<style type="text/css">
body { font-family: Helvetica, sans-serif; }
h2, h3 { margin-top:0; }
form { margin-top: 15px; }
form > input { margin-right: 15px; }
#results { float:right; margin:20px; padding:20px; border:1px solid; background:#ccc; }
</style>
</head>
<body>
<div id="results">Your captured image will appear here...</div>
<h1>WebcamJS Test Page</h1>
<h3>Demonstrates simple 320x240 capture & display</h3>
<div id="my_camera"></div>
<!-- First, include the Webcam.js JavaScript Library -->
<script src="https://cdnjs.cloudflare.com/ajax/libs/webcamjs/1.0.26/webcam.min.js" integrity="sha512-dQIiHSl2hr3NWKKLycPndtpbh5iaHLo6MwrXm7F0FM5e+kL2U16oE9uIwPHUl6fQBeCthiEuV/rzP3MiAB8Vfw==" crossorigin="anonymous" referrerpolicy="no-referrer"></script>
<form method="POST" enctype="multipart/form-data" id="myForm">
<table>
<tr>
<td>Name/EmailId</td>
<td>: <input type="text" name="userID"></td>
</tr>
<tr>
<td><input type="button" value="Upload" onclick="upload()"></td>
</tr>
</table>
</form>
<div id="my_camera"></div>
<input type="button" onclick="snap()" value="Snap">
<div id="results"></div>
</body>
<script>
function ShowCam() {
Webcam.set({
width: 320,
height: 240,
image_format: 'jpeg',
jpeg_quality: 100
});
Webcam.attach('#my_camera');
}
window.onload= ShowCam;
function snap() {
Webcam.snap( function(data_uri) {
// display results in page
document.getElementById('results').innerHTML =
'<img id="image" src="'+data_uri+'"/>';
} );
}
function upload() {
console.log("Uploading...")
var image = document.getElementById('image').src;
var form = document.getElementById('myForm');
var formData = new FormData(form);
formData.append("file", image);
var xmlhttp = new XMLHttpRequest();
xmlhttp.open("POST", "/Test");
// check when state changes,
xmlhttp.onreadystatechange = function() {
}
xmlhttp.send(formData);
console.log(formData);
console.log(formData.get('file'));
console.log(formData.get('userID'));
}
</script>
Test2.html
<!DOCTYPE html>
<html>
<body>
<h1>My First Heading</h1>
<p>My first paragraph.</p>
<p> {{data}}
</body>
</html>

Unstable result in jsp while using javascript

I am currently working in jsp. I need to get the value of input on text box while a buttton is clicked. My code is given below. While running it produces output which disappears in seconds. I need a stable output (text in textbox) when button is clicked.
<html>
<head>
<style type="text/css">
body {
background-color: #cccccc;
}
tab{ padding-left: 4em; }
</style>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<form>
<title>Businesscard Management</title>
</head>
<body>
<br><br><br><br><br><br>
<h2> Search : <input type="text" class="textbox" size="75" id="myText" autofocus="true" name="searchinput"/></h2>
<button onclick="myFunction()">Try it</button>
<p id="demo"></p>
<script>
function myFunction() {
document.getElementById("myText").value="ertyu";
}
</script>
</body>
</html>
First of all you have some errors in your code markup. You have just one opened <form> tag inside of <head> tag. Also I noticed that you're trying to set styles for tab but this is not appropriate tag. And you forgot to close </html> tag. Be careful when writing code, better to use code indention for better reading and it could prevent plenty of errors.
regarding your code:
<html>
<head>
<style type="text/css">
body {
background-color: #cccccc;
}
tab {
padding-left: 4em;
}
</style>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Businesscard Management</title>
</head>
<body>
<br><br><br><br><br><br>
<form action="/">
<h2> Search : <input type="text" class="textbox" size="75" id="myText" autofocus="true" name="searchinput"/></h2>
<input type="button" onclick="myFunction()" value="Try it"/>
<p id="demo"></p>
</form>
<script>
function myFunction() {
document.getElementById("myText").value = "ertyu";
}
</script>
</body>
</html>
I've move <form> tag to it desired position. And replaced <button> with <input type="button"> to prevent form submitting. So regarding your code when you press Try it button you will assign "ertyu" text to the input value. And if you want to get value of it, just use document.getElementById("myText").value

JavaScript - Toggle CSS colors with plain JavaScript?

I'm trying to change the colors of a form text field back and forth, using plain javascript. Can somebody help?
I can change the color once but not back
Here is what I have done
<!DOCTYPE html>
<html>
<head>
<title>JavaScript</title>
</head>
<body>
<script type="text/javascript">
function color() {
var x = document.getElementById("currID");
if(x.style.color="red") {
x.style.color="blue";
}
}
}
</script>
<input type="button" value="Click Me" id="testButton" onclick="color()" />
<form method="get" action="getresult.php">
<p>Current ID: <input id="currID" class="a" type="text" name="currID" /></p>
<p><input type="submit" value="Request new ID"/></p>
</form>
</body>
</html>
CSS
<style type="text/css">
.main {
color:black;
}
.a {
color:red;
}
</style>
Try this:
<!DOCTYPE html>
<html>
<head>
<title>JavaScript</title>
</head>
<body>
<script type="text/javascript">
function color() {
var x = document.getElementById("currID");
if(x.className == "main"){
x.className = "a";
} else {
x.className = "main";
}
}
</script>
<input type="button" value="Click Me" id="testButton" onclick="color()" />
<form method="get" action="getresult.php">
<p>Current ID: <input id="currID" class="a" type="text" name="currID" /></p>
<p><input type="submit" value="Request new ID"/></p>
</form>
</body>
</html>
CSS:
<style type="text/css">
.main {
color:black;
}
.a {
color:red;
}
</style>
Demo: https://jsfiddle.net/a5rxoh03/
Specifically to your issue, and why it didn't work, is because when adding a 2nd IF, you just reveresed the result.
Check out this fiddle, it will change the input field of the "currID" as requested from blue to red and vice verca.
https://jsfiddle.net/0rnnqe3y/
This is the JS :
function color() {
var x = document.getElementById("currID");
console.log(x.style.color == "red");
if(x.style.color=="red") {
x.style.color="blue";
return;
};
if(x.style.color=="blue"){
x.style.color="red";
return;
}
}

progress bar in public google drive upload

I have a code that allows my website users to upload to a central Google Drive account. So far it works great, I am simply trying to add in a progress bar.
Here, is the form HTML I have, I have been able to add a progress bar, it just does not move from 0%.
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>JS File Upload</title>
<style>
.container {
width: 500px;
margin: 0 auto;
}
.progress_outer {
border: 1px solid #000;
}
.progress {
width: 20%;
background: #DEDEDE;
height: 20px;
}
</style>
<form id="myForm">
<input type="text" name="myName" placeholder="Your name..">
<input type="file" name="myFile">
<input type="submit" value="Upload File"
onclick="this.value='Uploading..';
google.script.run.withSuccessHandler(fileUploaded)
.uploadFiles(this.parentNode);
return false;">
</form>
<div id="output"></div>
<script>
function fileUploaded(status) {
document.getElementById('myForm').style.display = 'none';
document.getElementById('output').innerHTML = status;
}
</script>
<style>
input { display:block; margin: 20px; }
</style>
Besides that, I did some more research and have found a template example, I am just not sure how to implement it correctly into my existing code. Here is what I found from Caja Playground.
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>jQuery UI Progressbar - Default functionality</title>
<link rel="stylesheet" href="http://code.jquery.com/ui/1.8.23/themes/base/jquery-ui.css">
<script src="http://code.jquery.com/jquery-1.8.2.js"></script>
<script src="http://code.jquery.com/ui/1.8.23/jquery-ui.js"></script>
<link rel="stylesheet" href="http://jqueryui.com/resources/demos/style.css">
<script>
$(function() {
$( "#progressbar" ).progressbar({
value: 37
});
});
</script>
</head>
<body>
<div class="demo">
<div id="progressbar"></div>
</div><!-- End demo -->
<div class="demo-description">
<p>Default determinate progress bar.</p>
</div><!-- End demo-description -->
</body>
</html>
Hm, You only put the html file , where is the gs file ? also Its not possible unless you use chunk to upload ^^
You can use external libraries like MediaUploader js file. See the following tutorial. It includes every functions such as Create folder, upload file, view images, view content image text, show share files only etc.
Demo of using Google Drive API

Canvas trouble changing color/clearing canvas on button click

My code is using a canvas that allows people to draw whatever they want, what I'm trying to implement is changing the color of what their coloring on button click, default color is black I have two buttons to change ot red and green and also a clear canvas button, none of these seems to operate on button click however.
<h3>Draw Something</h3>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Paint Canvas</title>
<style type="text/css">
<!--
#container { position: relative; }
#imageView { border: 1px solid #000; }
-->
</style>
</head>
<body>
<div id="container">
<canvas id="imageView" width="600" height="300">
</p>
</canvas>
</div>
<script type="text/javascript" src=".js"></script>
</html>
<body >
<input type= "button" value= "Green" id= "green" onclick= "GreenRect()" />
<input type= "button" value= "Red" id= "red" onclick= "RedRect()" />
<input type= "button" value= "clear canvas"
id= "clear" onclick= "ImgClr()" />
<button id="howdy">Howdy!</button><br>
</body>
function GreenRect () {
context.strokeStyle= 'green';
context.stroke();
}
function RedRect () {
context.strokeStyle= 'red';
context.stroke();
}
function ImgClr () {
context.clearRect(0,0, 600, 300);
}
</script>
You did have a lot of mis-formed html, like a second <body> tag as well as a </html> half way through your code, either of which would have completely confused a browser as you can see by Firefox's noble attempt to make sense of your code:
<html lang="en"><head></head><body><h3>Draw Something</h3>
<meta charset="utf-8">
<title>Paint Canvas</title>
<style type="text/css">
<!--
#container { position: relative; }
#imageView { border: 1px solid #000; }
-->
</style>
<div id="container">
<canvas id="imageView" width="600" height="300">
<p></p>
</canvas>
</div>
<script type="text/javascript" src=".js"></script>
<input type="button" value="Green" id="green" onclick="GreenRect()">
<input type="button" value="Red" id="red" onclick="RedRect()">
<input type="button" value="clear canvas" id="clear" onclick="ImgClr()">
<button id="howdy">Howdy!</button><br>
function GreenRect () {
context.strokeStyle= 'green';
context.stroke();
}
function RedRect () {
context.strokeStyle= 'red';
context.stroke();
}
function ImgClr () {
context.clearRect(0,0, 600, 300);
}
</body></html>
Also there is:
an <h3> tag outside of your <body> tag
your javascript at the bottom of your original code is outside of the <body> and <head> tags as well as lacking an opening <script> tag.
<p></p> tags within your canvas tags that don't seem to be doing anything.
I'd strongly recommend not looking at my code below, but first just trying to clean up your html according to the comments I've made about it. I think you would get a lot out of doing that for yourself.
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Paint Canvas</title>
<script type="text/javascript">
//declare global namespace
this.DGN = {
prep: undefined,
context: undefined,
greenRect: undefined,
redRect: undefined,
imgClear: undefined,
smileyFace: undefined
};
DGN.prep = function(){
if(typeof DGN.context === "undefined") {
var canvas = document.getElementById('imageView');
if (canvas.getContext){
DGN.context = canvas.getContext('2d');
}
}
};
DGN.greenRect = function () {
DGN.prep();
DGN.context.strokeStyle = 'green';
DGN.context.stroke();
};
DGN.redRect = function () {
DGN.prep();
DGN.context.strokeStyle = 'red';
DGN.context.stroke();
};
DGN.imgClear = function () {
DGN.prep();
DGN.context.clearRect(0, 0, 600, 300);
};
DGN.smileyFace = function () {
DGN.prep();
console.log(DGN.context);
DGN.context.beginPath();
DGN.context.arc(75,75,50,0,Math.PI*2,true); // Outer circle
DGN.context.moveTo(110,75);
DGN.context.arc(75,75,35,0,Math.PI,false); // Mouth (clockwise)
DGN.context.moveTo(65,65);
DGN.context.arc(60,65,5,0,Math.PI*2,true); // Left eye
DGN.context.moveTo(95,65);
DGN.context.arc(90,65,5,0,Math.PI*2,true); // Right eye
DGN.context.stroke();
};
</script>
</head>
<body>
<h3>Draw Something</h3>
<div id="container">
<canvas id="imageView" width="600" height="300">
</canvas>
</div>
<input type="button" value="Green" id="green" onclick= "DGN.greenRect()" />
<input type="button" value="Red" id="red" onclick= "DGN.redRect()" />
<input type="button" value="clear canvas" id="clear" onclick= "DGN.imgClear()" />
<input type="button" value="Smiley Face" id="smileyFace" onclick= "DGN.smileyFace()" />
</body>
</html>

Categories