Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 8 years ago.
Improve this question
I am working on a mobile application, I am trying to make an image as a button: I have an image and I want to click on it, then when I click the mobile gallery opens so that I can upload a photo.
Any help please?
I think, you want to open file-uploader on image button click! Right?
If so, you can use pure javascript / jQuery as following:
HTML:
<div id="profilepic">
<input id="fileSelector" type="file" name="file" accept="image/*" capture="camera" />
<button id="clickButton" onClick="openFileUpload();"><img src="Images/profilepic.png" width="170" height="170"/></button>
</div>
For jQuery append this to head of your document:
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
Wrap following code in head too.
JQuery:
$(document).ready(function(){
$('#clickButton').on('click', function(){
$('#fileSelector').click();
});
});
OR Javascript:
function openFileUpload(){
document.getElementById('fileSelector').click();
}
http://jsfiddle.net/mas5qr1o/1/
See demo here:
jQuery DEMO
Javascript DEMO
Try the following jquery
$('#clickButton').on('click', function(){
$('#fileSelector').trigger('click');
});
DEMO
Related
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 17 hours ago.
This post was edited and submitted for review 17 hours ago.
Improve this question
I have them both as HTML files in my repo. The button is just meant to switch from pages for now. I will add the function for the inputs and conditions later. I just want to get in working before I add anything. There are also no errors that or popping up. I cannot use a tag as I need to change the URL to pass data through it, so I need to have it in JS so I can change it with the data from the input.
The plan is to have the user put in their name in a text input, and have it inside the Url, then have the 2nd page process the name and output a text and photo.
This is the code that I have tried.
const nameButton = document.getElementById("nameBtn");
$(nameButton).click(function(){
preventDefault()
function change_page(){
window.location.replace("page-two.html");
};
change_page()
});
This is the Html:
<input class="font" type="text" id="inputName" value="Type in
your name..."></input>
<button class="fonts" id="nameBtn">Ready?</button>
</form>
</div>
</body>
<script src="scripts/script.js"></script>
</html>
Short answer, only replace the pathname
window.location.pathname = 'page-two.html'
In your case:
const nameButton = document.getElementById("nameBtn");
nameButton.addEventListener('click', function (event) {
event.preventDefault()
window.location.pathname = "page-two.html";
});
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 4 years ago.
Improve this question
Sorta like
when you click the button, you get the favicon.ico from the link (using js)
an example ico would be stackoverflow favicon
//this is the js section
//some way to read the text box and Retrieve favicon from link
<button Id=button Onclick=<!--add Update favicon function here -->
Favicon.ico</button>
<input type=box id=field text="input Text here">
If I understand what you're asking correctly, this should work:
function updateFavicon(link){
let exists = $("link[rel*='icon']");
if(exists.length){
$("link[rel*='icon']").attr('href', link);
} else {
$("head").append("<link rel='icon' href='" + link + "'>");
}
}
And then:
<script src="//ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js"></script>
<div>
<input type="text" id="link">
<button onclick="updateFavicon($('#link').val())">Update Favicon</button>
</div>
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 4 years ago.
Improve this question
<script>
function addMoreAns() {
$(".add").append("<h1>Hi</h1>")
}
</script>
It is my jquery tag in javascript function.
jquery tag don't work under javascript function
You must have three things for your code to work:
You must make sure to have the JQuery library referenced prior to your use of any JQuery code.
In the HTML, you must have an element that is allowed to contain content with an add class.
You must invoke your function somehow. Just writing a function isn't the same thing as running it. You have to decide when the function should run and set up your code to invoke it at that point.
In the example below, the function is invoked every time the button is clicked.
document.querySelector("input[type=button]").addEventListener("click", addMoreAns);
function addMoreAns() {
$(".add").append("<h1>Hi</h1>")
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<input type="button" value="Click to Add">
<div class="add"></div>
You need to load the jQuery library in the head of your page
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
</head>
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
How to paste JavaScript/jQuery code in blogger post?
Such like jsfiddle.net/tTman
It didn't work, don't know what I miss?
Please guide me the correct way to achieve my objective .
(Newbie learning)
My guess would be that you did not load the jquery library. Pasting the following code in the HTML view of a blog-post should work:
<img id="b" src="http://www.web-press.it/folder/servizi_cloud.jpg" id="b" style="position:absolute; top:50px"/>
<!-- Loading the required JQuery library -->
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<script>
function moveRight(){
$("#b").animate({left: "+=300"}, 2000,moveLeft)
}
function moveLeft(){
$("#b").animate({left: "-=300"}, 2000,moveRight)
}
$(document).ready(function() {
moveRight();
});
</script>
follow this path:
blogger.com -> Template -> Edit HTML
and past your javascript/jquery codes before </head>
<script type="text/javascript">
function moveRight(){
$("#b").animate({left: "+=300"}, 2000,moveLeft)
}
function moveLeft(){
$("#b").animate({left: "-=300"}, 2000,moveRight)
}
$(document).ready(function() {
moveRight();
});
</script>
see pic:
now!
go to Layout and add a gadget and input your HTML code into that!
<img id="b" src="http://www.web-press.it/folder/servizi_cloud.jpg" id="b" style="position:absolute; top:50px"/>
see pic:
Notice:
you must add Jquery libararies before your Jquery codes
if you want to show this effects only in posts, go to
blogger.com -> New Posts
and in edditor box, click on HTML and past your HTML Codes into that
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
I have two page page1.php, page2.php and one JS file Control.js.
In page1.php
HTML :
<img src="images/b.jpg" width="31" height="26" id="imgClick1" onClick="return changeImage1(this)" >
In Control.js
function changeImage1() {
document.getElementById("imgClick1").src = "images/b.jpg";
document.getElementById('num1').style.color = "#fff";
document.getElementById("text1").innerHTML = "Hello friend";
}
In page2.php
<div id="text1">
Hello world
</div>
So using JavaScript I am trying to write "hello friend" in the div "text1" of page page2.php when I click the image or the div of page1.php.
Is there any possible way to use JS to solve this problem?
Can we use any how document.getElementById("text1").innerHTML or something like that in the program?
I suggest you make use of the include function of php (provided you absolutely want to keep your text1 div on a separate page), like this on your page1.php file:
include('page2.php');
Make sure that when you do that, page1.php and page2.php are in the same folder, otherwise you may define a path to it like this:
include('/path/to/page2.php');