javascript variable not populated correctly [closed] - javascript

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 6 years ago.
Improve this question
Basically, the "rec" variable is correctly filled, but it's not happening with the "email" variable . Why?
This is my code:
<textarea id="q" name="q"></textarea>
<button onclick='alert(rec);'>Click</button>
<a id="email" href="#" target="_blank">Email</a>
<script>
var rec;
var email;
$("#q").keyup(function() {
rec = $('#q').val();
email = 'www.corriere.it/' + rec;
$('email').attr("href", email);
});
</script>
https://jsfiddle.net/wvsc93d4/3/

You're not using the selector correctly, try:
$('#email').attr("href",email);

You're missing the # selector:
$('#email').attr("href",email);

Related

How can I make this take the text they put in the input box and then put it into local storage [closed]

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 2 years ago.
Improve this question
i don't understand why it doesn't send what they put in the input box to local storage
<body>
<input id="name">
<button onclick="bob()">
save
</button>
</body>
<script>
const person = document.getElementByid("name");
window.localStorage.setItem('user', JSON.stringify(person));
</script>
You need to use the value property to get what the user entered.
function bob() {
const person = document.getElementById("name");
window.localStorage.setItem('user', person.value);
}

Why does the following class selector in cheerio doesn't function? [closed]

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 3 years ago.
Improve this question
js code :
...
let wr = $('div[class="topstory-content-wrapper last"]');
console.log(wr.html());
...
error: throw new SyntaxError("Malformed attribute selector: " + selector);
^
SyntaxError: Malformed attribute selector: class = topstory-content-wrapper last
Try to write your selector in the next way:
const wr = $('div.topstory-content-wrapper.last');

How do I make an alert() that prints out the value of a variabile? [closed]

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 4 years ago.
Improve this question
I'm trying to make an alert, that prints the value of a variabile, here is my attempt.
var username = prompt("I'm LaunchBot, what's your name?");
var print = alert() ;
alert() is a function. It take a parameter between the parenthesis. So just insert your variable username between them:
var username = prompt("I'm LaunchBot, what's your name?");
alert(username) ;
As suggested in the comment alert() doesn't return anything so do not add a variable assignment before.

Javascript backgroundColor works on some computers, not on others? [closed]

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 6 years ago.
Improve this question
This part of javascript code works on my home computer, but doesn't at work. Also, my colleague tested it and it doesn't work on her home computer?!
function klikNaX(x, y, z) {
var u = document.getElementById(z);
var u2;
u2 = u.style.backgroundColor;
document.getElementById("test").innerHTML = (z + " " + u2);
}
The problem seems to be with this part
u.style.backgroundColor;
Its not a problem of style.backgroundColor, instead please check if 'u' is a valid node and not undefined.
And try setting a color to u.style.backgroundColor = 'green'

Why this JavaScript code does not work? [closed]

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 7 years ago.
Improve this question
This code should working, but I have no idea why it is not working at all.
HTML:
<p><input type="file" size="50"></p>
<p><input type="button" value="test" onclick="test()"></p>
JavaScript:
test = function() {
console.dir(document.querySelector('input[type="file"]').value);
var a = document.querySelector('input[type="file"]').vaule;
console.dir(a);
};
The first console.dir can successfully display the selected file filename
whereas I store it in var a is return undefined, whats happended?
fiddle: jsfiddle.net/eb5tuo7o
With the console log you're using .value but when you're storing it you've misspelled it as .vaule.
test = function() {
console.dir(document.querySelector('input[type="file"]').value);
var a = document.querySelector('input[type="file"]').value;
console.dir(a);
};
There is no such thing as "vaule"
You can access html elements value by using
document.querySelector('input[type="file"]').value;
And if you are using jquery it's even simpler
$("input[type=file]").val();

Categories

Resources