I have a local Drupal 7 website and an article with a button in it.
I want, when the button is clicked to run a MySQL query and save username and email of the user who clicked the button.
Can I do this with JavaScript? This is the html of the button and the js script I have created at the bottom of the article edit:
<button id="test" value="test" onclick="Press()">Press Here</button>
<script>
function Press() {
var test= document.getElementById("test");
test.innerHTML="Thank you";
localStorage.value=("ok");
}
</script>
Related
For a project I'm trying to create a button that has 2 goals :
-1Copy a value in the clipboard of the user
-2Redirect the user to another url
I found a way to make both seperatly but I'm not able to find a way to do both at the same time
Here is the html code I'm using :
<!DOCTYPE html>
<html>
<body>
<input type="hidden" value={{t}} id="myInput">
<p></p>
<button onclick="myFunction()">Home</button>
<script>
function myFunction() {
// Get the text field
var copyText = document.getElementById("myInput");
// Select the text field
copyText.select();
// Copy the text inside the text field
navigator.clipboard.writeText(copyText.value);
// Redirect to my other website
window.open("my_other_website", "_blank");
}
</script>
</body>
</html>
If I comment the line " window.open" myinput gets in the user clipboard but unforunatly if I leave the "window.open" the redirection is made but without the value in the clipboard...
If anyone has solution about this thank's in advance...
i'm trying to write an Opera extension. I need to add a page to favourites when user click submit button.
For example there is a web page:
<html>
....
<input id="button-submit" type="submit" value="Submit" onclick="doSomething();">
...
</html>
and i want to make an extension that provides additional action (create bookmark) when user click submit. I wrote something, but it doesn't work:
var button = document.getElementById('button-submit');
button.addEventListener("click", function() {
chrome.bookmarks.create({'parentId': 1,
'title': 'My extension'});
});
Please help :)
I'd like to have a click on a button reload the page and change the text inside the button.
For reload I got:
Javascript:
function reloadPage(){
window.parent.location = window.parent.location.href;}
HTML:
<button type="button" onClick="reloadPage()">Start</button>
<script src="reloadpage.js"></script>
After click, the text in the button must change from "Start" to "Try Again!"
How can I do this?
Thank you.
You could do this by adding a query string on reload, and then have a script that detects the query string and changes the text of the button onload.
JavaScript:
function reloadPage(){
window.parent.location = window.parent.location.href+"reload=true";}
function checkQString(){
// get query strings and store reload qstring in variable
if (reload) {
document.getElementById('btn').innerHTML = 'Try Again!';
}
HTML
<button id='btn' type="button" onLoad='checkQString();' onClick="reloadPage()">Start</button>
<script src="reloadpage.js"></script>
You can use Cookies. With js you can use https://plugins.jquery.com/cookie/ Or can use server side cookies
I sent a mail via google script which sends button in email body, I want to update a spreadsheet when button in email body is clicked.I am unable to trigger the function present in script.
myfunction1 is used to send the email with button in body.
function myfunction1() {
var htmlBody = HtmlService.createHtmlOutputFromFile('mail_template').getContent();
MailApp.sendEmail({
to: Session.getActiveUser().getEmail(),
subject: 'Testing Gmail action:',
htmlBody: htmlBody,});}
body in mail_template
<html>
<body>
<p id="demo"></p>
<div>EMAIL CONTENT GOES HERE<br/></div>
<form>
<input type="button" id='mybtn' onclick="google.script.host.updatesheet()" value ="click me"/>
</form>
</body>
</html>
updatesheet is the function used to update the spreadsheet.
function updatesheet()
{
var spreadsheetkey = "1q2hgrZZCR1ytQEX-irUQWjXg5g6YNaRwcfsTQq7UZ30";
var sheet = SpreadsheetApp.openById(spreadsheetkey).getActiveSheet();
var lastrow = sheet.getLastRow();
sheet.getRange(lastrow+1, 1).setValue("testing");
}
you are calling google.script.host.updatesheet from the form in the email, which will be fully outside of the apps script, thus the browser has no idea where that function is. if you debug the click to the button you would have seen browser errors.
look at the docs for building a content service. your button form must post to that service url.
I have an article (Full Html) and I have a button. I want, when the button is clicked, to create a cookie and remember that the button is clicked. This is the code I currently have:
<button id="test" value="test" onclick="Press()">Press</button>
<script>
function Press() { text
}
</script>
How should I create the press function? This is the HTML of the article
function Press() {
document.cookie="button=pressed";
}
document.cookie will create a cookie..