How to auto save html textarea without button? [closed] - php

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 3 years ago.
Improve this question
I have a textarea in my html like this:
<textarea id="area1"></textarea>
When visitors copy/paste or type something in this area i want it to save to a txt file without the visitor having to click any button.
Looked all over the web but can't find any solution.

write JS function, that saves info in .txt file. Let's say, function name is saveToTxt(). Then trigger that function onChange:
<textarea id="area1" onChange="saveToTxt(this);"></textarea>
EDITED
Assume that, saveToTxt() is something like that:
<script>
function saveToTxt(fld) {
const textAreaValue = fld.value;
// then use textArea variable as container of textarea-content
// and then treat it as you want.
}
</script>

This example show how to save content automatically 2s after changing. It can prevent from doing save for every character typed.
var t;
function save() {
clearTimeout(t);
t = setTimeout(function() {
console.log('All changes saved'); // save here
}, 2000);
}
<textarea onchange="save();" onkeyup="save();"></textarea>

Related

How to call a function from button inside echo in php? [closed]

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 2 years ago.
Improve this question
I am trying to pass a variable from one php function to another.
1st function creates a button.
2nd function needs to be able to receive variable that button sent to the 2nd function.
Nothing happens when i click the button. Page just flickers.
<?php
function myFunc(){
$filename = "123";
echo '<form method="post"><input type="submit" name="button1"class="button" value="Button1" onclick="myOtherFunc("tomato")" /></form>';
}
myFunc();
function myOtherFunc($filename){
echo '$filename'."anyting ?" ;
}
Onclick will not execute php code. PHP code is executed on the server BEFORE your page is rendered. Once your page is rendered, the only code that can be executed without reloading the page is Javascript. The onclick attribute on your button will look for a Javascript function called func_ImageView, which does not exist. If you want the content if your func_ImageView function to be called, you need to call that code in php, but you should instead use javascript for this from what it looks like.

Hide div before login [closed]

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 5 years ago.
Improve this question
I have a table with add, edit, delete options. Now I want to hide divs with buttons for not logging users.
Or maybe I should make a deactivated buttons for not loggin users?
when user login then you have session like
$_SESSION['email']=$email;
then used this code
<?php
if(isset($_SESSION['email']))
{
echo "<div>any text</div>";
}
?>
do some effort to write the code
Depending on how your site works there are two possible solutions that I can think of.
USE PHP
If the user is logged in then use:
<?php
if ($logged_in) {
?>
<div>Your text here</div>
<?php
}
?>
NOTE: You do not need to use "echo" or "print" if you close and open your PHP tags between the "if" as shown below. This can make the HTML part of the much easier to read and write.
USE JAVASCRIPT
If the page does not reload when the user logs in then you will need to use Javascript to hide and show the DIV using something like:
var x = document.getElementById("myDIV");
if (x.style.display === "none") {
x.style.display = "block";
} else {
x.style.display = "none";
}

Using php condition and javascript hide the div's [closed]

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 5 years ago.
Improve this question
I just messed up with is a problem from the last couple of hours and still didn't get the solution i m new in php.what I m trying to do is display and hide the dive according to php condition.
here is the scenario:
note: by default DIV(display:none)
if(condition is satisfied ) //condition in PHP only
//call the javascript function which displays the div
else
//call the javascript function which hides the div
if you have the solution with example please must share it's a humble request
thank you
You want to mix Javascript, HTML and CSS as little as possible. It might look easier to mix it right now, but that will change as you get more experience.
There are multiple ways, but one I prefer is running PHP and passing the variables to a JS variable and let JS decide:
const showSpecificElement = <?php echo funtionWhichDoesSomething(); ?>;
if( showSpecificElement ){
// Javascript magic here
}
// Or, alternatively:
if(<?php echo funtionWhichDoesSomething(); ?>){
// Javascript magic here
}
// Or, slightly better:
$classWhichHidesThisDivOrNot = rand(1,2)==1 ? 'hideMe' : 'showMe';
<div class="<?=$classWhichHidesThisDivOrNot?>"> ... </div>

PHP, let user know that leave blank text field is not allow [closed]

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 9 years ago.
Improve this question
I'm changing for this website's sake...I'm trying to explain that I need something to let registrar create the register form, then if leave oe textbox blank, the click on submit, then JavaScript's alert to tell registrar to fill the blank textbox. I need this in PHP. Thank you for help in advance.
Gary
I didn't see a javascript tag within your question. You can check to see if the text area has been set before writing the database.
<?php
$textArea = $_POST['textAreaName'];
$error = false;
if($_POST) {
if(isset($textArea)) {
// run code and write to DB
} else {
$error = "Please fill out text area";
}
}
?>
HTML
<form.......>
<?php echo $error ? $error :"" ?>
<textarea></textarea>
</form>
Use javascript on the front-end, like so:
if(document.getElementById('InputId').value == ''){alert('fill in the blanks');}
You should always do a check using PHP as well:
if(!isset($_GET['InputId']) || empty($_GET['InputId'])){return false;}

jQuery prepend() function alternative in php [closed]

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 9 years ago.
Improve this question
I want to switch a task of jQuery to PHP.
Earlier it was like :
myString += "Hello There ! ";
$("#latestRoutes").prepend(myString).slideDown(2000);
But now As I am switching to PHP, How can I do the $.prepend function in PHP to append a variable to a particular string ?
On page load if the variable isset then show it as a first child of your div like this:
<div>
<?php if(isset($mystring)) echo '<p class="test">'.$mystring.'</p>'; ?>
<p>...</p>
<p>...</p>
</div>
but since this is php is served only on page refresh and of course you cannot have fancy js animations at once, some extra work needs to be done. If you want this to communicate with js add a class there and with js check its existence and then start its animations. This can be done like:
if($('.test').length > 0) {
alert("This message is brought by php, great!!!");
$('.test').on('click', function(){
$(this).hide();
});
}

Categories