Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
I would like to know how you add a function that clears the contents in the textarea if something is typed. For example, the standard message in the textarea would say: "Type something...", but if something is typed, the textarea would be cleared. Basically, the same function that Facebook uses in their wallpost-textarea.
And how do I make the height of the textarea automatically follow the amount of text, so no scrollbar is needed. Again, the same function that Facebook uses in their wallpost-textarea.
Actually, I've noticed that the function that clears the contents in the textarea/input field is used on this site's signup page, when you entering your e-mail, password etc.
I hope that some of you can help me. I've tried to find a script about it but without any luck!
The first thing is a (HTML5) placeholder attribute. It is a message that is there by default and when you start typing it goes away.
http://www.w3.org/html/wg/drafts/html/master/forms.html#the-placeholder-attribute
For the second one you need some JavaScript.
$('textarea').on('keyup',function(e){
$(this).css('height',$(this).get(0).scrollHeight);
});
Probably not the best solution but you could try something like the following.
<script>
function textAreaAdjust(o) {
o.style.height = "1px";
o.style.height = (25+o.scrollHeight)+"px";
}
</script>
<textarea cols="50" id="textAreaAdjust" style="overflow:hidden" placeholder="Type something..." onkeydown="textAreaAdjust(this)"></textarea>
jsfiddle example
Related
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
I need to be able to have my main page (index.php) check every 10 seconds for a change in the mysql database table 'refresh'. If the 'refresh' value is 1 it needs to refresh the page in its entirety. If the value is zero it does nothing. I would use meta-refresh but I cannot have the page always refreshing as the page has a slider and it would mess up the rotation. Please let me know what you think of! Thanks in advance!
Use AJAX to check if an update is required.
http://api.jquery.com/jQuery.ajax/
You should learn the basic how to's of AJAX before using something like jQuery when you don't even know what's going on.
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Closed 8 years ago.
This question appears to be off-topic because it lacks sufficient information to diagnose the problem. Describe your problem in more detail or include a minimal example in the question itself.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Improve this question
I want to know if it is possible with PHP to make action only happen once.
I have a script where users click an image and gain points for clicking it, but I would like to make it so that if they click again it won't add points anymore for a certain amount of time, or an advertisement would disappear from the site for that particular user.
Is this possible?
Store it in the database.
When they click on the image, run a query that changes the is_clicked column (for instance) to clicked or 1 or whatever you like.
Retrieve the image in such a way that, if the is_clicked column is changed to clicked for a particular user, then don't allow any clicks.
For example :
if($row['is_clicked'] != 'clicked']){
echo '<img>....</img>';
}
It is possible but with PHP, it can get pretty messy. I would suggest you use JS (Javascript). Create a simple function in JS and then use the onclick attribute in the the button element to execute. Like this:-
<script>
document.getElementById('id of the button').onclick='myFunc';
function myfunc(){
document.getElementById('id of the button').style.display="block";
}
</script>
Front end, html:
<button id="id of the button">Click here!</button>
Now if you want to make sure a person who clicks button from a computer shouldn't be able to click it again, then you should set up a cookie using php which will retrieve data about its computer and prevent the computer from using this button
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
I just want to ask if possible to call an image using php? For example I have homepage that has 1 div for image (pic1) then after two weeks I will change the image into (pic2). How can I accomplish it without going to my cpanel to change the code . Are there any program or languages that can help me to do that? I am trying to do the back-end side of my homepage to change the images.
Changing images is very simple. If you want to do it automatically, you could setup a CRON job or use PHP's date function. If you want to do it manually, by selecting a button, you can do it like this:
<script>
function changeSrc() {
document.getElementById("myImage").src="imageName.jpg";
}
</script>
<body>
<img id="myImage" src="otherImage.jpg" width="107" height="98">
<br><br>
<input type="button" onclick="changeSrc()" value="Change image">
</body>
http://nl1.php.net/manual/en/function.date.php
You can use PHP's date() function in combination with an if/else statement to determine what picture to use.
Example:
if(date('d-m-y') == 'yourdate'){
//Show picture 1
}
Next to that, with a little searching you could've figured this out on your own perfectly fine ;)
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
So I currently have a PHP script that is being called from an HTML link. The script is set up such that it needs to accept non-user input from the page (static data that already exists). The line that calls the script looks like this.
<div class="Name">Text</div>
I need to pass the values in "Name" and Text to the script, as well as another value from an earlier line.
What would be the best way to accomplish this? All of my research points to using forms and GET/POST, but as you can see, there is no place for the user to input any of the data. Is there any way to do this using hidden forms or AJAX?
If you're the author of the web page, you'd use javascript and an onclick event to capture the div class and the anchor's text, and send it via ajax (or directly if your script provides some sort of user output or redirect back to the calling page) to your script as a post event. the data could be conveniently formatted as a json structure to simplify the script's processing.
By using the GET method :
<div class="Name">Text</div>
Maybe this code well help
<div class="Name"><a id="link" href="some/script.php">Text</a></div>
<input id="name" onblur="modify(this.value)">
<script type="text/javascript">
var link = document.getElementById("link").href;
var modify = function(name){
var a = document.getElementById("link");
a.href = link + "?name="+name;
}
</script>
In the href attribute for the link, do something like this:
href="some/script?name=George&text=All This Stuff"
This will make the information available in the $_GET[] array in the PHP script.
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Closed 8 years ago.
This question appears to be off-topic because it lacks sufficient information to diagnose the problem. Describe your problem in more detail or include a minimal example in the question itself.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Improve this question
I've seen sites where instead of form buttons, they use links like that
onclick="USER._like('161', this);"
And when I click on it, it dynamically inserts the data into the database.
What is this called? And are there any tutorials around here?
Thanks.
That is a javascript event handler. Presumablly the function USER.like ( or to be exact the method like on the object USER) makes an ajax call and sends the value 161 to the server which is then somehow recorded.
That said its much better to do it in an unobtrusive manner, meaning that you would not write function call into an html attribute but rather attach an even handler pragmatically from javascript... using assuming this html:
<a class="like-button" href="#" data-id="161">Like</a>
Achieving the same thing in an unobtrusive manner with jquery would look like:
$(function (){
$('.like-button').on('click', function (e) {
e.preventDefault();
USER.like($(this).attr('data-id'), this);
});
});