Missing a step? [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
I'm trying to do a basic math function and change the contents of a <p></p> element but when I click the button, it does nothing.
I know it's something trivial but I thought this would work.
What am I missing?
HTML
<button onclick="doMath()">Click</button>
<p id="output"></p>
JavaScript
function doMath() {
var total = 6/2(2+1);
document.getElementById("output").innerHTML = total;
}

function doMath() {
var total = (6/2*(2+1));
document.getElementById("output").innerHTML = total;
}
<button onclick="doMath()">Click</button>
<p id="output"></p>

Related

How does using variables in javascript 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 1 year ago.
Improve this question
I have some simple code here, and I want to test it out, by making the display none, is there something wrong with my javascript? (I'm very new to js)
var meter = document.getElementById("meter").innerHTML;
meter.style.display = "none";
<meter id="meter" min="0" max="10"></meter>
The console says meter is undefined, but I defined it right above.
meter is the innerHTML of the element (which is a string), not the element itself.
Instead, use:
var meter = document.getElementById("meter");
meter.style.display = "none";
<meter id="meter" min="0" max="10"></meter>
If you want to hide it and get its value, you can do:
var meter = document.getElementById("meter");
meter.style.display = "none";
var val = meter.value;
console.log(val)
<meter id="meter" min="0" max="10" value="3"></meter>

Why can't I change the name attribute of this input? [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
So I have an ol with several li like this:
<ol id="monday">
<li id="zero1"><input type="hidden" name="mo[]" value="cero1"><button type="button"">15</button></li>
</ol>
<button type="button" onclick="update()"> Update</button>
And I can change the content of the ol, but when I try to change the name attribute with jquery it remains the same, Is there something wrong with my function?
function update(){
$("#monday input").each(function (){
$("this").attr("name", "mo[]");
});
}
this is a keyword and it should not be a String here
function update(){
$("#monday input").each(function (){
$(this).attr("name", "mo[]");
});
}

Get id from class selector without click [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Closed 4 years ago.
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.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Improve this question
I want to get the id from a class selector without clicking.
var type_selected = '' ;
$('.type_selected').attr();
type_selected = (this.id);
Use this. This will return an array of all elements with that class;
var type_selected = [];
$('.type_selected').each(function(){
type_selected.push($(this).attr("id"));
});
console.log(type_selected);
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<p class="type_selected" id="id1">This is a test<p>
<p class="type_selected" id="id2">This is a test 2<p>
<p class="type_selected" id="id3">This is a test<p>

How to get <option> from <select> by its index? [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
I'm having here a <select> that looks like this:
<select id="stdin-select" class="io-byte-box" size="10">
<option>0x5232</option>
<option>0xFD13</option>
<option>0x13E7</option>
<option>0x1234</option>
<option>0xFFFF</option>
</select>
and I am trying to access the values by its index like this:
var stdinValue = $('.stdin-select.dropdown option').eq(0).text();
and this
var stdinValue = $('.stdin-select option').eq(0).text();
like described here but it's not working.
What am I doing wrong here?
Change class (.) to id ('#')
var stdinValue = $('#stdin-select option').eq(0).text();
In your example there is not element with class stdin-select, instead there is element with if stdin-select

Iframe content not displaying [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
I am trying to create an iframe in which the content changes based on a button click. However the iframe is not displaying any content. Could someone take a look at my code and explain why.
<script>
int i = 0;
var array= ["news1.html","news2.html","news3.html"];
function setURL(){
if (i<2) {
i = i+1;
}
else{
i=0;
};
document.getElementById("iframe").src = array[i];
}
</script>
<iframe id="iframe" style="float:right;" width="770" height="360"></iframe>
<button type="button" onclick="setURL()" style="float:right;"> Next </button>
I know it's not the best code in the world but as far as I can tell it should work so I was hoping for a hand with it please?
change your variable declaration from:
int i = 0;
to:
var i = 0;
Everything worked once i changed that.

Categories