This question already has answers here:
Is "clear" a reserved word in Javascript?
(4 answers)
Why can't I call a function named clear from an onclick attribute?
(3 answers)
How to clear a textbox using javascript
(15 answers)
Closed 4 years ago.
I only know how to use Javascript and HTML5
I have tried so many ways to clear textarea but they won't work
<textarea id="texti" placeholder="Place Text Here Or Paste Text"></textarea>
<button class="button" type="button" onclick="clear()">CLEAR</button>
<script type="text/javascript">
function clear(){
document.getElementById("texti").innerHTML= "";
}
</script>
in the function part I have tried
document.getElementById("texti").value=0;
document.getElementById("texti").value="";
but apparently none of theme works in my code
End your textarea tag
Use .value
Do NOT use reserved words like clear
function clearIt() {
document.getElementById("texti").value = "";
}
<textarea id="texti" placeholder="Place Text Here Or Paste Text">XXX</textarea>
<button class="button" type="button" onclick="clearIt()">CLEAR</button>
Related
This question already has answers here:
Django Template Variables and Javascript
(18 answers)
Closed last month.
I'm trying to generate a code for editing posts using modal that are made before
but it shows "Identifier or string literal or numeric literal expected" and "Statement expected" ERROR
here is my code:
`
function submitHandler(){
const textareaValue = document.getElementById("textarea_"${post.id}).value
</script>
<button type="button" class="btn btn-secondary"onclick=submitHandler({{post.id}}) > Save Changes</button>
`
want to submit change to editing posts.
if your are sending the textarea id via onclick, so didn't need to get it again via jinja or django template.
<script>
function submitHandler(post_id){
my_textarea = 'textarea_'.concat(post_id);
const textareaValue = document.getElementById(my_textarea).value
</script>
<button type="button" class="btn" onclick=submitHandler({{post.id}})> Save Changes</button>
This question already has answers here:
Why this JSFiddle does not work [duplicate]
(1 answer)
jsFiddle: no connection between html and js? Can't call simple function from button? [duplicate]
(1 answer)
Closed 5 years ago.
ive used a basic example from w3schools.com to get here:
https://jsfiddle.net/02wu0v49/
function myFunction() {
var x = document.getElementById("fname").value;
document.getElementById("demo").innerHTML = "aaaaaa";
document.getElementById("fname").value = "bbbbb";
alert("lala3");
}
<body>
<p>A function is triggered when the user releases a key in the input field. The function outputs the actual key/letter that was released inside the text field.</p>
Enter your name: <input type="text" id="fname" onkeyup="myFunction()">
<p>My name is: <span id="demo"></span></p>
</body>
somehow the w3schools version works but it wont do anything on jsfiddle?
and it would be really nice to use [code][/code] or something to format code on stackoverflow...all those indents are terrible.
Change load type to No wrap in - <body>
Here is updated fiddle
Here is Docs
If you open the browser console in JS fiddle it lists the error. The HTML can't find the JS.
This question already has answers here:
what's the difference between <a onclick="someFunction"> and <a onclick="someFunction()">
(3 answers)
Closed 6 years ago.
I'm very new to HTML and JavaScript. I have seen onclick been assigned to function with following parentheses onclick="confirmOnSubmit() and functions without following parentheses onclick="confirmOnSubmit.
I was just wondering what is the difference between the two? When should I use one over the other?
<input type="submit" value="Submit" id="submitID" onclick="confirmOnSubmit()"/>
using parentheses after a function name means invoking that function.However, using it without a parentheses just means the function itself.
<input type="submit" value="Submit" id="submitID" onclick="confirmOnSubmit()"/>
so in your example, it is basically saying that whenever the submit btn is clicked, invoke the confirmOnSubmit function.
<input type="submit" value="Submit" id="submitID"/>
document.getElementById('submitID').onclick=confirmOnSubmit
however, in the above example, we don't want to call the function at that moment, we just want to assign a reference, so that it can be called later on when the event happens.
hope it helps.
This question already has an answer here:
Select option base on property key in value
(1 answer)
Closed 6 years ago.
I have this button in HTML , with a property defined by me on it (data-filter-params):
<button class="button" type="submit" data-filter-params="{'Type', 'Filter.Type'},{'Code','Filter.Code'}" >Filter</button>
How can I take with JavaScript\JQuery the value for data-filter-params
plain javascript
var btn = document.getElementsByClassName('button')[0];
console.log(btn.dataset.filterParams)
jQuery
console.log($('.button').data('filter-params'));
This should solve it
var value
$(function(){
value = $('button').attr('data-filter-params')
})
JSfiddle: https://jsfiddle.net/mayank_shubham/3k97gg9k/
It's very easy,
HTML:
<button id="btnSubmit" class="button" type="submit" data-filter-params="{'Type', 'Filter.Type'},{'Code','Filter.Code'}" >Filter</button>
jQuery:
var attr = $('#btnSubmit').attr('data-filter-params');
alert(attr)
This question already has answers here:
Why does jQuery or a DOM method such as getElementById not find the element?
(6 answers)
Closed 8 years ago.
I am very new to javascript. I am trying to place value on one input field. But it is not working, I don't know why..
document.getElementById("c_add").value='sssssss';
in the text area with id "c_add", I supposed that value will place as "sssssss", but it is not setting any value..
Full Code:
<body>
<script type="text/javascript">
document.getElementById("c_add").value='sssssss';
</script>
<textarea name="c_add" id="c_add"></textarea>
</body>
Did you tried do like this?
<input type="text" id="mytext">
<script type="text/javascript">
var elem = document.getElementById("mytext");
elem.value = "My default value";
</script>