Make button disappear permanently [closed] - javascript

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 4 years ago.
Improve this question
I have a situation, when the user clicks a button in page A the button will disappear and go to page B. and when the user goes back to page A, the button will still disappear. Is it possible to do this? Is this sounds logical?
<table>
<tr>
<th>Booking Number</th>
<th>checkin</th>
<th>checkout</th>
<th>Num. of days</th>
<th>Total Charges</th>
<th>Breakfast</th>
<th>accommodation ID</th>
</tr>
<c:forEach items="${books}" var="book">
<tr>
<td><c:out value="${book.bookingnum}" /></td>
<td><c:out value="${book.checkin}" /></td>
<td><c:out value="${book.checkout}" /></td>
<td><c:out value="${book.numofdays}" /></td>
<td><c:out value="${book.totalcharges}" /></td>
<td><c:out value="${book.bfast}" /></td>
<td><c:out value="${book.accid}" /></td>
<td>
<form name="reserveSubmitForm" method="post" action="Payment1Controller?action=createPayment&bookingnum=<c:out value="${book.bookingnum}"/>">
<input type="submit" class="btn btn-primary btn-block" value="Pay">onclick="style.display = 'none'"
<input type="hidden" name="totalcharges" id="totalcharges" value="${book.totalcharges}"/>
</form>
</td>
</tr>
</c:forEach>
</table>

When the button is clicked, you can set a value in sessionStorage. Also, on page load, check to see whether that value exists in sessionStorage, and if it does, hide the button. For example:
foo
JS:
const a = document.querySelector('a');
if (sessionStorage.clickedA) a.style.display = 'none';
a.addEventListener('click', () => {
sessionStorage.clickedA = 'clicked';
});
https://jsfiddle.net/qfsuLyc3/
I don't think cookies are a good idea because it's information that seems to be only relevant for the client, not the server. (cookies will be sent to the server)
sessionStorage persists over a page session. If you want the button to be hidden even after the browser is reopened, use localStorage instead, which uses the file system, rather than memory, and is persistent.

If you want this on a temporary basis, you can use GET method. You can pass an additional value in the URL from page two to page one, and check if the value is present or not.
Example:
Go To Page One
On the first page, check the presence of the movingback (I am using php to do the same)
<?php if(!isset($_GET['movingback']) || !$_GET['movingback']=='true'){
echo "<a href='pagetwo.php'>Go To Page Two</a>"
}

Related

How create a Directory WHIT PHP and HTML whit a Button?

Hello i have a problem... Suppose that i have a table whit two textBox and one button.. when i click the button i must read the value of a textBox and create a directory in a specific path and the directory must be named like the value that i read on the TextBox
I've tryed this code but it dosn't work :(
file = directory.php
<?php
$idCantiere = $_POST["idCantiere"];
$codiceCommessa = $_POST["codiceCommessa"];
echo("Registrazione avvenuta");
chdir("../inserimento");
opendir(".");
mkdir("../inserimento/prova/".$idCantiere);
?>
file prova.html
<table method="POST" action="directory.php">
<tr>
<td bgcolor="#B2E5FB">Cantiere</td>
<td colspan="11"> <input type="text" id="idCantiere"></td>
</tr>
<tr>
<td bgcolor="#B2E5FB">Codice Commessa</td>
<td colspan="11"> <input type="text" id="codiceCommessa"></td>
</tr>
<tr><td><button name="insAffidatario" type="submit" onclick="directory.php">Inserisci Affidatario</button></td></tr>
</table>
The problem with your code and it is a specific one; is that you used <table></table> for what should be a form, it should be <form></form>.
Then you used ID's instead of name attributes. You need to add name="idCantiere" and name="codiceCommessa" to their respective inputs.
You may also want to remove onclick="directory.php" here. The "action" already takes care of that.
Side note: Place your table inside the form and not outside. <form> cannot be made child of <table>.
Also make sure that the paths (and folders) correspond and that they are writeable with proper group/user permissions.
Error reporting will be of help also.
http://php.net/manual/en/function.error-reporting.php
and set to catch and display.

chrome displaying correctly the view, but saying "notice: undefined variable..." in source code when I inspect it. How to fix? [closed]

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 5 years ago.
Improve this question
PHP/HTML code
<td width="12%" align="right" bgcolor="#F5E4A9">TITOLO</td>
<td width="88%" bgcolor="#F5E4A9"><input name="pagetitle" type="text" id="pagetitle" size="80" maxlength="255" value="<?php echo $pagetitle; ?>" onkeyup="getTitle()"/></td>
</tr>
<tr>
<td align="right" bgcolor="#D7EECC">SOTTOTITOLO<br>(facoltativo)</td>
<td bgcolor="#D7EECC"><input name="linklabel" type="text" id="linklabel" size="80" maxlength="255" value="<?php echo $linklabel; ?>" onkeyup="content()"/>(se riempito, sarĂ  utilizzato anche come anteprima per GOOGLE)</td>
</tr>
<tr>
<td align="right" valign="top" bgcolor="#DAEAFA">TESTO</td>
<td bgcolor="#DAEAFA" valign="top" align="center">
<textarea name="pagebody" id="pagebody" class="MCEeditor" cols="88" rows="16" onkeyup="getPagebody()">
<?php echo $pagebody; ?>
</textarea>
</td>
rendering by chrome
source code according to chrome
And I think It gets some of my scripts not to work because they come back to work when I remove notice notifications and put rendered values in their place.
This just means that the variables you have used is not defined. This is either because of a typo or that you have not created the variables
EDIT:
As Frithjof mentions;
The scope you are rendering to the is not aware of $pageBody. If you have defined $pageBody in the global scope and the html rendering is done in a function, you have to use the variables in a special way. Check out this link about (variable) scopes and read more on your favorite php tutorial website. Anyway, global variables are not best practice. You should avoid using them wherever you can. Parsing variables via parameters is better

Hide row when checkbox is checked [closed]

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 5 years ago.
Improve this question
Hi guys hope you are doing well.Actually I want to hide a row when the checkbox within the row is checked and my codes are not working. Help please!Thanks
MY HTML CODE:
<table id="test">
<tr>
<td><label value="name">Name</input><br><input type='text'></input></td>
<td><label value="name">LastName</input><br><input type='text'></input></td>
<td><input type='checkbox'></input></td>
</tr>
<tr>
<td><label value="name">Name</input><br><input type='text'></input></td>
<td><label value="name">LastName</input><br><input type='text'></input></td>
<td><input type='checkbox'></input></td>
</tr>
<tr>
<td><label value="name">Name</input><br><input type='text'></input></td>
<td><label value="name">LastName</input><br><input type='text'></input></td>
<td><input type='checkbox'></input></td>
</tr>
</table>
</body>
MY JS CODE:
<script>
$(document).ready(function()
{
$('input[type=checkbox]').(change(),function()
{
if (this.checked)
{
$("#test tr").attr("hide", true);
}
});
});
</script>
Actually I want to hide a row when the checkbox within the row is
checked and my codes are not working.
There seems to be multiple issues with your code
$('input[type=checkbox]').on("change",function() //change() changed to "change"
{
$(this).closest("tr").hide(); //observe changes in this line
});
Explanation
unless change() returns "change", your event handler will not be invoked on change event
You don't need to handle if(this.checked) since once your checkbox's value is changed, it won't be visible
Just find the closest tr and hide the same. $("#test tr").attr("hide", true); will simply add a hide attribute to all rows

How to send textarea who contains html using Jquery $.ajax [duplicate]

I have a non complicated issue......that seems to be more complicated than it should be.
I have a simple form that is used to add content to a website. Some of the fields need to have html inputted into them. However, when you input certain html elements into the different parts of the form, it decides that it hates you and throws a forbidden 403 error. Here is the form below:
<?php
$data = f("SELECT * FROM table WHERE id = '{$_GET['id']}'");
?>
<form action="<?=$_SERVER['PHP_SELF']?>?id=<?=$_GET['id']?>&action=edit" method="post">
<table cellspacing="0" cellpadding="2" border="0">
<tr>
<td><b>Title:</b></td>
<td><input type="text" name="title" style="width: 300px;" value="<?=$data['title']?>" /></td>
</tr>
<tr>
<td><b>URL:</b></td>
<td><input type="text" name="url" style="width: 300px;" value="<?=$data['url']?>" /></td>
</tr>
<tr>
<td><b>Sub-Category:</b></td>
<td>
<select name="subCategoryId">
<option value=""></option>
<option value="1">A</option>
<option value="2">B</option>
</select>
</td>
</tr>
<tr>
<td><b>Short Description:</b></td>
<td><textarea name="shortDescription" rows="6" cols="60"><?=$data['shortDescription']?></textarea></td>
</tr>
<tr>
<td><b>Template:</b></td>
<td><textarea name="template" rows="6" cols="60"><?=$data['template']?></textarea></td>
</tr>
<tr>
<td><b>Ads:</b></td>
<td><textarea name="ads" rows="6" cols="60"><?=$data['ads']?></textarea></td>
</tr>
<tr>
<td><b>Keywords:</b></td>
<td><textarea name="keywords" rows="6" cols="60"><?=$data['keywords']?></textarea></td>
</tr>
<tr>
<td><b>Questions:</b></td>
<td><textarea name="questions" rows="6" cols="60"><?=$data['questions']?></textarea></td>
</tr>
<tr>
<td><b>Salary:</b></td>
<td><textarea name="salary" rows="6" cols="60"><?=$data['salary']?></textarea></td>
</tr>
<tr>
<td><b>Jobs:</b></td>
<td><textarea name="jobs" rows="6" cols="60"><?=$data['jobs']?></textarea></td>
</tr>
<tr>
<td><b>Meta Description:</b></td>
<td><input type="text" name="metaDescription" style="width: 300px;" value="<?=$data['metaDescription']?>" /></td>
</tr>
<tr>
<td><b>Meta Keywords:</b></td>
<td><input type="text" name="metaKeywords" style="width: 300px;" value="<?=$data['metaKeywords']?>" /></td>
</tr>
<tr>
<td> </td>
<td><input type="submit" name="submit" value="Edit Job" /></td>
</tr>
</table>
</form>
I have other forms that follow this same pattern without any trouble. To further make this even more confusing, it will only throw this error when any 2 html elements are supplied in the text area (it handles one html element just fine). The text areas are ads, keywords, salaries, and jobs. The other text areas will take it just fine, but these 4 won't. If I can make this one more bit confusing, if I simple enter in text in those fields and save it, it runs without a problem.
To handle the post data, I only use mysql_real_escape_string() to handle the data, I don't do a strip_tags() as I need the html in there.
Is this a weird apache error that can be fixed with .htaccess? Is there a module in PHP that is conflicting with this?
-------EDIT HERE IS THE ANSWER--------
Ben brought up a fantastic answer that is probably the problem and I cannot fix it because of a lack of privileges. So I created an onsubmit event from an idea that Gerben gave me and wrote the following javascript.
function awesome() {
elements = document.forms[0].elements;
for(var i = 0; i < elements.length; i++) {
switch(elements[i].name) {
case "ads":
case "shortDescription":
case "template":
case "questions":
case "salary":
case "jobs":
str = elements[i].value;
elements[i].value = str.replace(/</g,"##!");
break;
}
}
return true;
}
Then on the receiving end, I did a str_replace to replace ##! back to a < and that at least made the thing work.
I'm on a horse....hyaa!
Thanks for all your help. :)
Given that you're able to post, and that your post-handling is apparently extremely simple and so unlikely to be throwing 403 errors or redirecting to forbidden directories, I'm going to hazard a guess that you're running an apache-level firewall. Have a look at your apache config files, and check to see if you're running mod_security or any other firewall module loaded. There are a number of ways mod_security can be configured, including scanning POST data for html content and reacting accordingly. If it is configured to prevent html injection, this may be your issue (see configuration details here: http://www.modsecurity.org/projects/modsecurity/apache/feature_content_injection.html).
To test this, try adding an htaccess file into your web root (assuming you're allowed to override apache settings with htaccess) and setting:
SecFilterEngine Off
Restart apache and then see if it's still happening.
If this is a shared host, or you otherwise don't have the ability to modify apache settings, you can try a workaround using javascript that base64 encodes all the data before submitting (onsubmit), and then base64_decode($_POST[key]) in the php script that processes it.
<IfModule mod_security.c>
SecFilterEngine Off
SecFilterScanPOST Off
</IfModule>
Use This Code I Think This Solved Your Problem
Just had the same sort of issue on submit showed 403 error but for me it was simple because the form was too big triggering a rule on mod_security.
Also worth increasing php.ini post_max_size and test size using: $_SERVER['CONTENT_LENGTH']
In my case, disabling MOD security in cPanel solved the issue for me.
<IfModule mod_security.c>
SecRuleEngine Off
SecRequestBodyAccess Off
</IfModule>
<IfModule mod_security.c>
SecFilterEngine Off
SecFilterScanPOST Off
</IfModule>
after add this on my htaccess file the problem solve.
Might be abit late, but I faced a similar problem today while trying to submit a form through POST. It would not allow me to submit a text with a link and would throw a 403 Forbidden Acess Denied error.
Disabling modsecurity (I did this from the control panel) solved it!
The issue is caused by the Apache Firewall mod, it can also be fixed via .htaccess file if you cannot or dont want to edit the httpd.conf.
Create or edit the existing .htaccess file in the directory where the script is called (usually where the index.php is) and add the following lines:
<IfModule mod_security.c>
#SecRuleEngine Off
SecRequestBodyAccess Off
</IfModule>

JS verify form data inside ajax-returned html

Ajax-returned HTML includes a table and a submit button (type=button)
The table includes jQuery routine to clone table row (each row allows choosing/uploading one file, and has two values: <input type="text"> for doc title, and <input type="file">.
<table id="MyTable">
<tr name="tr3" id="tr3">
<td>
<input type="text" name="dt[]" id="dt1">
</td>
<td>
<input type="file" name="fff[]" id="ff1">
</td>
</tr>
</table>
<input type="button" name="sub1" id="sub1" value="Submit" onclick="checkform();">
Upon form submit, I must check that each doc title has been filled-in, so the submit button calls a javascript routine:
function checkform()
{
if(document.updateprojectdocs.dt[0].value=='')
{
alert("Fields marked with an asterisk are required.");
document.updateprojectdocs.dt[0].focus();
return;
}
document.getElementById("TheForm").submit();
}
Of course, this does not work (script dies before form submit -- but submits if I remove the preceeding if structure). Can anyone tell me why and how to fix?
Also, there will be an indeterminate number of dt[] fields to check. How could I structure a loop to do this? I suspect jQuery's .find().each() could be used, but not sure what that would look like?
UPDATES:
Thanks to DaHaKa's response below, I am closer to a solution. I mod'd DaHaKa's suggested code into jQuery.
I was having trouble communicating with DaHaKa - for some reason his responses were not appearing until long, long, long after he posted them (the problem was probably on my end). While I was waiting (hours), I posted part of the problem in another question and ended up resolving it there. That other question grew into the FULL CORRECT ANSWER, and I direct future viewers there. Note that user thecodeparadox created a working JSFiddle of the full solution.
I have awarded this question to DaHaKa as he was more than willing and able to assist, but comm problems intervened. Thanks again, D.
In this case jQuery each function isn't neccessary, you can do it simple like this =>
try
<table id="MyTable">
<tr name="tr3" id="tr3">
<td>
<input type="text" name="dt" id="dt1">
</td>
<td>
<input type="file" name="fff" id="ff1">
</td>
</tr>
</table>
<input type="button" name="sub1" id="sub1" value="Submit">
JavaScript
document.getElementById("sub1").onclick = function(){
if (document.getElementById("dt1").value!=""){
document.getElementById("TheForm").submit();
} else {
alert("Empty Field(s) !");
}
};
you should use ids in JavaScript from html tags , NOT NAME tags
And whats about you file input , you could understand it from your server side scripting language like php , with super global variables $_FILES['file']['error'] types

Categories

Resources