sessionStorage from input - input

Can someone please tell what's wrong with this code?
Even when I change sessionStorage.setItem("item1"; document.test.value); to a fixed value like sessionStorage.setItem("item1"; "test"); it does nothing.
Is it a problem in the code or some browser setting?
The browser gives undefined for sessionstorage.
<!DOCTYPE html>
<html>
<head>
<script type="text/javascript">`
function Session()
{sessionStorage.setItem("item1"; document.test.value);}
function Show()
{alert("Value 1 is " + sessionStorage.getItem("item1"));
}
</script>
</head>
<body>
<input type="text" id="test">
<button type="button" onclick="Session()">invoer</input>
<button type="button" onclick="Show()">show</input>
</body>
</html>

You have a semicolon where it should be a comma on this line:
{sessionStorage.setItem("item1"; document.test.value);}
Should be:
{sessionStorage.setItem("item1", document.test.value);}

Related

Changing paragraph content with button

Forgive my ignorance, because I'm pretty new to programing. I've been beating out my brains on this one. Can anyone tell me why this doesn't work? I know it will be something dumb:
addText(){
document.getElementById("demo").innerHTML = "New Content";
}
<!DOCTYPE html>
<html>
<head>
<title>InnerHTML Example</title>
</head>
<body>
<p id="demo">
<Button onclick="addText()">Change</Button>
Original Content
</p>
</body>
</html>
You haven't declared addTest() as a function. Should be:
<script>
function addTest() {
...
}
</script>
function addText() {
document.getElementById("demo").innerHTML = "New Content";
}
<!DOCTYPE html>
<html>
<head>
<title>InnerHTML Example</title>
</head>
<body>
<p id="demo">
<Button onclick="addText()">Change</Button> Original Content
</p>
</body>
</html>

How can I use libraries when using router in riot.js?

I'm developing my application with riot.js and I want to use dropzone(http://www.dropzonejs.com/).
In my code:
index.html below,
<!doctype html>
<html>
<head>
<meta charset="utf-8">
</head>
<body>
<app></app>
<script src="dist/scripts/bundle.js"></script>
</body>
</html>
app.tag below,
var route = require('riot-route'); require("dropzone"); require('./main/home.tag'); require('./main/contents1.tag');
<app>
<main>
<contents></contents>
</main>
<script>
route(function(tagName) {
tagName = tagName || 'home'
riot.mount('contents', tagName)
})
route.start(true)
</script>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/dropzone/4.3.0/min/dropzone.min.css" />
</app>
home.tag below,
<home>
<div class="search-box"></div>
</home>
Then, I add <form action="/file-upload" class="dropzone" id="my-awesome-dropzone"></form> into app.tag like this, it works right.
<contents></contents>
<form action="/file-upload" class="dropzone" id="my-awesome-dropzone"></form>
but, I add it into home.tag like this,
<home>
<div class="search-box"></div>
<form action="/file-upload" class="dropzone" id="my-awesome-dropzone"></form>
</home>
it doesn't work. Can anyone help me??
Try to update DropZone when mounting the tag, using on('mount', or also you can try with on('updated',
<home>
<div class="search-box"></div>
<form action="/file-upload" class="dropzone" id="my-awesome-dropzone"></form>
<script>
this.on('mount', function(){
new Dropzone(".dropzone");
})
</script>
</home>

How to create asp:table when click on add button

How to genera dynamic table it constant asp:textbox and sum other controls, when click on button in javascript.
Try This Code:
<html>
<head>
<script>
function changeLink()
{
document.getElementById('myAnchor').innerHTML="<table style='width: 100%'><tr><td> <input type='Text'/></td></tr></table>";
}
</script>
</head>
<body>
<div id="myAnchor">
</div>
<input type="button" onclick="changeLink()" value="Change link">
</body>
</html>

Angular with readonly input

I'm trying to trigger on-change on a readonly input. I can't find an alternative way to do it.
<!DOCTYPE html>
<html ng-app="angularjs-starter">
<head lang="en">
<meta charset="utf-8">
<title>Custom Plunker</title>
<script src="//ajax.googleapis.com/ajax/libs/angularjs/1.0.5/angular.min.js"></script>
<link rel="stylesheet" href="style.css">
<script>
document.write('<base href="' + document.location + '" />');
</script>
<script src="app.js"></script>
</head>
<body ng-controller="MainCtrl">
<form>
<input type="text" ng-change="changeRO()" ng-model="input" readonly placeholder="I have readonly attribute." />
<input type="text" ng-change="change()" ng-model="input" placeholder="Write" />
<p ng-repeat="text in texts">{{text}}</p>
</form>
</body>
If your input is readonly than that means the user cannot directly change its value. And if user cannot do that than the onchange event will never be fired. Same stands for cases where you're changing the values dynamically, - the onchange event won't be fired.
In your case, since your read/write inputs are connected to 'input' model (through ng-model), you can trigger your 'changeRO' callback from $watch function in your controller:
$scope.$watch('input', function(){
$scope.changeRO();
});

Pass Javascript Alert a Value

I'm looking for a simple javascscript alert box. I need to be able to pass the alert box a string of text.
Is something like this possible? My syntax is probably wrong.
<html>
<head>
<script type="text/javascript">
function show_alert()
{
alert(my_string_here);
}
</script>
</head>
<body>
<input type="button" onclick="show_alert()" value="Show alert box" string="alert for system number 2" />
</body>
</html>
<html>
<head>
<script type="text/javascript">
function show_alert(my_string)
{
alert(my_string);
}
</script>
</head>
<body>
<input type="button" onclick="show_alert('This will alert!')" value="Show alert box" string="alert for system number 2" />
</body>
</html>
This makes no sense thou. Better solution:
<html>
<head>
</head>
<body>
<input type="button" onclick="alert('Doh!')" value="Show alert box" string="alert for system number 2" />
</body>
</html>
Try:
<input type="button" onclick="alert('alert for system number 2');" value="Show alert box" />
What are you trying to do? alert('Your string here') should do the trick if you really need an alert.
Yes you can
function testAlert(val){alert(val);}
Yes this is possible
<script type="text/javascript">
function testAlert(val){alert(val);}
</script>
<input type=text onclick='testAlert(this.string)' string="something" value="clik here">
alert("alert for system number 2");