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)
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:
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>
This question already has answers here:
How do I get jQuery to select elements with a . (period) in their ID?
(8 answers)
Closed 4 years ago.
Hi guys ive got a button with jquery like this :
<html>
<button id = "index.php">
</button>
</html>
<script>
$('#index.php');').click(function(){
//stuff
});
</script>
however it seems that the id with a "." isnt accepted by jquery - is there a way to make it work?
Try escaping the .
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<button id = "index.php">
</button>
<script>
$('#index\\.php').click(function(){
console.log('stuff');
});
</script>
This question already has answers here:
What do querySelectorAll and getElementsBy* methods return?
(12 answers)
Closed 4 years ago.
My task is to inject a custom JS function to an HTML code where we cannot edit buttons and HTML it self, just inject some custom HTML code through GUI. What I have in the code:
<input class="ContinueAsAGuest LinkButton" name="submitForm" type="submit" value="Continue as a guest >" />
What I need:
<input class="ContinueAsAGuest LinkButton" name="submitForm" type="submit" value="Continue as a guest >" onclick = "captureOutcome()" />
I wanted to use DOM, but I failed, I stay get the original code. This what I have:
var guest = getElementsByClassName("ContinueAsAGuest LinkButton");
guest.onclick = "captureOutcome()";
function captureOutcome(
{'eventName':'event registration','eventAction':'start' }
);
I am guessing what I miss is to add the actual onclick to the original code.
Am I on the right path?
You need to use document.getElementsByClassName to get the element with that class name and if that is a unique class then use [0] to get the reference of that element. By getting the reference you can associate a click function into it.
var guest = document.getElementsByClassName("ContinueAsAGuest LinkButton")[0];
guest.onclick = captureOutcome;
function captureOutcome(){
alert('clicked!');
};
<input class="ContinueAsAGuest LinkButton" name="submitForm" type="submit" value="Continue as a guest >" />
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>