Closed. This question needs debugging details. It is not currently accepting answers.
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.
Closed 4 years ago.
Improve this question
This may seem as a dumb question, but I just can't figure out, what am I doing wrong?
I have a HTML textarea which always contains one simple sentence. What am I trying to achieve is to load this sentence into JS variable with the help of ".value;"
But when I try to print out the variable, it's always empty - Screenshot from the console
Can you please tell me, what am I doing wrong, or at least point me the right direction?
Thanks in advance!
Textareas have a different behavior that inputs. Their value is stored inside the opening and the closing tags.
Here is an example :
alert(document.getElementById('textarea').value);
<textarea id="textarea">I am the value !</textarea>
Also next time, please include your code and the result as text, not as an image.
Use this:
alert(document.getElementById('separator').value)
<textarea id="separator">Lorem ipsum</textarea>
value for a textarea is the value enclosed between the tags <textarea></textarea. In your case that is ''. Hence, you get an empty string.
You 'd be better off if you included some text between the tags. I am sure you will get the result you need then.
Related
Closed. This question needs debugging details. It is not currently accepting answers.
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.
Closed 2 years ago.
Improve this question
I have in my JS code, some lines with binde, what is it? Why is it working and what does it mean?
On example with, type="checkbox":
if (document.binde.nameofthecheckbox.checked)
{
//...its true whens checked and do the code
}
or
somevar = document.binde.somehtmltagname.value;
somevar gets the value of "somehtmltagname"
No one can answer me, I only heard "never seen something like that before". I would be happy to know what it is, and not only using it because it works.
It is not well known, but document might define HTML elements with id specified as document[HTMLElement.ID] as such, if there is an <input id="binde"> on the page, it will point to that.
If not, try logging it:
console.log(document.binde)
Closed. This question needs debugging details. It is not currently accepting answers.
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.
Closed 2 years ago.
Improve this question
So, I have an array with 200 items called "icone", and when I use this code:
icone.attr('src', 'img/known.svg');
All items change according to what is in the code.
But how do I do if I want to change only 1 of the items in this array, and not all 200?
I tried with:
icone[0].attr('src', 'img/known.svg');
But the console returned "icone[0].attr is not a function".
Any ideas on how to make this work?
Thanks!
If it is absolutely necessary to use jQuery in this case. You can do this:
$(icone[0]).attr('src', 'img/known.svg');
In case it is not, you can do it as the other answers say.
Once you do icone[0], you're dealing with a raw node, not a jQuery "wrapper." That raw element does not have an .attr function.
As Ouroborus suggests, just set the attribute directly by doing icone[0].src = ....
(If Ouroborus submits an answer in addition to their comment, you should mark it as accepted, not this answer. I just wanted to explain why what you're doing doesn't work.)
EDIT: Interestingly, icone.first().attr(...) does work, because it does wrap the first element with a jQuery wrapper.
Closed. This question needs debugging details. It is not currently accepting answers.
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.
Closed 5 years ago.
Improve this question
I've would like to make a really simple form validation is JS.
I've created a function with if statements inside,while everything is ok it should display nothing and when something is not right (number in a name input for e.g)
a message under a certain input should be displayed.Right now it sometimes work,sometimes not.
If anybody could look at my code and tell me what's wrong would be really helpful
Here's my live version
Here's the code
You are using name="name-surname" twice (in two different input tags), which prevents the values to be sent properly. Use the same values for name as the values for the IDs
Closed. This question needs debugging details. It is not currently accepting answers.
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.
Closed 7 years ago.
Improve this question
I'm trying to generate HTML using PHP and have that HTML printed out and displayed on a site for a user to then copy and paste elsewhere. My problem, however, is that whenever I try to use print or echo statements and type in the HTML, the HTML is being rendered instead of simply just printed. I even put the HTML as a string into a variable and tried printing/echoing that variable but it was also rendered. Is there any way to literally just have the words I'm typing (which happen to be HTML) printed or displayed in some way on the page in a box or something of the sort?
if I understood your question, I think you should use htmlentities():
print htmlentities('<br>');
This wil show the tag instead of generate a new line.
Closed. This question needs debugging details. It is not currently accepting answers.
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.
Closed 8 years ago.
Improve this question
I asked a question a few days back, and the link below was the solution in JSFiddle:
http://jsfiddle.net/vineetgnair/pnhxxcsw/11/
Later on, I got another answer that did the work of the previous solution in just 2 lines of code instead of 8-9. Since I'm new to coding, I'm unable to figure out how the new JSFiddle works. If someone could explain it to me, I would be appreciative.
Here is the code and JSFiddle link from the second solution:
var div = $('div').not(':first').hide().end();
$('button').on('click', function() { div.hide().eq($(this).index()).show() })
http://jsfiddle.net/adeneo/pnhxxcsw/13/
Thanks in advance
the first line is very straight forward to read, we're getting all the divs, filtering them to get everything that is not the first child of it's parent, and hiding them, in other words, hiding everything except for first children.
the second line, we are adding a click event listener to buttons, and when we click, we show only the element with an index matching the clicked button
one more thing, just like the comments stated, check the jquery docs, that's the place to go in these cases