PHP - How to save the exact time and date when [closed] - javascript

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 6 years ago.
Improve this question
How can I save, in a database, the exact moment (time and date) when an user "tick" checkboxes?
I have 3 checkboxes to tick before proceeding with registration, and I need to save in the database the time and date when the user tick each checkbox (so 3 different times).

Use jquery, when the checkbox is clicked change the value of that checkbox and submit your form data..
function changeValue(id)
{
$('#checkbox'+id).val(new Date($.now()));
$('#span'+id).html('Clicked at '+new Date($.now()));
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<input type ='checkbox' id="checkbox1" name="a" onClick="changeValue('1');" >Checkbox 1
<span id="span1"></span><br>
<input type ='checkbox' id="checkbox2" name="b" onClick="changeValue('2');" >Checkbox 2
<span id="span2"></span><br>
<input type ='checkbox' id="checkbox3" name="c" onClick="changeValue('3');" >Checkbox 3
<span id="span3"></span>

The 'now()' keyword save the actual time...
If someone ticks the first box at 11:50AM and the second at 11:51AM, in the database must be inserted both different hour

at the time data save use "now()" which is mysql function.
you can set database table's column default value CURRENT_TIMESTAMP

I'm writing answer because i can't comment. You would need to use a javascript function to populate the value of the checkbox to the current time

Related

Is there any way that I can show a input bar in html? [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 2 years ago.
Improve this question
I made a website for a restaurant, the checkout page has 2 option, pay by cash and pay by card. Now if the user chooses to pay by card, then there will be no more input required. If the user chooses to pay by cash, then I need to let them enter their name. Is there any method I can show the input bar when the user chooses to pay by cash? I'm using python flask
You can use JS to do it, since it is supported on nearly all browsers.
function validate(){
var cashpay = document.getElementById("cash-pay");
var cardpay = document.getElementById("card-pay");
var name = document.getElementById("name");
if(cashpay.checked==true){
name.style.display='block';
}else{
name.style.display='none';
}
}
.hidden{
display:none;
}
<h1>What would you like to pay by?</h1>
<form>
<input type="radio" name="pay-method" id="cash-pay" oninput="validate()"><label for="cash-pay">Cash</label><input type="radio" name="pay-method" id="card-pay" oninput="validate()"><label for="card-pay">Card</label>
<input type="text" name="name" id="name" class="hidden" placeholder="Please enter your name:">
</form>
We can use the oninput attribute in the input types to make sure that our JS function validate() is run every time the user modifies their choice. We can use the .checked DOM element to check whether the input is checked. If it is, we can use .style.display='block' to display the input.

Adding more balance via a html input to a javascript variable? [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 4 years ago.
Improve this question
Photo of the website
I have a school project and I need to make a website where I can add more balance to my account. But I can't figure it out.
I would like to make an HTML number input and then that input needs to add up with my existing balance. But I can't make it work
This is the code I have:
<fieldset>
<legend>Opwaarderen</legend>
<input type="number" id="opwaarderen">
<input type="submit" onclick="opwaarderen()">
</fieldset
But how can I make the Javascript function? So that the input will add up to my already existing balance.
This will help
var currentCredit=0;
$("#a").click(()=>
{
alert(currentCredit+=Number($("#opwaarderen").val()));
})
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<fieldset>
<legend>Opwaarderen</legend>
<input type="number" id="opwaarderen">
<input type="submit" id="a">
</fieldset>

Multiple checkboxes to variable logic [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 am looking to create a simple page using HTML and (probably) PHP or JQuery. The page should allow for multiple checkbox selection, and give a variable a value based on which boxes are checked. This can be on submit or can render live on the page.
i.e.
Checkbox 1
Checkbox 2
Checkbox 3
If checkbox 1 is checked, variable = X
If checkbox 1 & 2 are checked, variable = Y
If no checkboxes are checked, variable = Z
What is the best way to approach doing this?
The best way would be using Javascript (because it'd be done live) but if you are doing this with PHP. The form would be something like
<form action='phplogic.php' method='post>
<input type="checkbox" name="checkbox1" value="Yes" />
<input type="checkbox" name="checkbox2" value="Yes" />
<input type="checkbox" name="checkbox3" value="Yes" />
<input type="submit" name="formSubmit" value="Submit" />
</form>
phplogic would would look like this
<?php
if(isset($_POST[checkbox1']) && (isset($_POST['checkbox2'])) {
$variable = 'Y';
} else (isset($_POST[checkbox1'])) {
$variable = 'X';
} else {
$variable = 'Z';
}
Although this doesn't address if checkbox 2 alone is checked but you get the point. You can do something very similar with javascript. https://www.w3schools.com/jsref/prop_checkbox_value.asp

PHP - Load a div with filtering option when two date fields are filled [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 8 years ago.
Improve this question
I have developed a leave request page with PHP,Javascript and CSS. I need when user choose the same date on two date fields then will show the div for a option with two radio buttons for halfday leave or fullday leave, please suggest me if any possibilities for this..
We can use jQuery's .val() method to check the date value. If two of them equal, then use .show() to display the extra elements, else use .hide() to not show them.
Start: <input type="date" name="s" id="s" onchange="check()"><br>
End: <input type="date" name="e" id="e" onchange="check()">
<div id="detail" style="display:none">
<select>
<option>Full day</option>
<option>Half day</option>
</select>
</div>
function check() {
if ($('#s').val() == $('#e').val()) {
$('#detail').show();
} else {
$('#detail').hide();
}
}
fiddle

the conditions radio button to another page after submit [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 making an application with PHP and javascript
There are 2 choices Yes and No.
When he chose NO option and submits, then going to the page "Thank You" and its data into the database. When selecting the YES option it will go to another page and its data into the database
<label class="radio inline"><input type="radio" name="choose" id="optionsRadios1" value="Yes">YES</label>
<label class="radio inline"><input type="radio" name="usia" id="optionsRadios2" value="No">NO</label>
<label class="control-label" for="">Nama</label>
<div class="controls"><input type="text" name="nama" ></div><input type="submit" name="submit" value="" class="btn next">
Try this,
function submitPage(url){
window.location.href=url;
}
$('input:radio').on('click',function(){
var url=this.value=='Yes' ? 'xyz.php' : 'abc.php';
submitPage(url); // or you can use ajax for post
});
Create a javascript function and fire it on the onclick event of the radiobutton passing the radio value in the parameter
And then in the function put condition for redirect and form submit
or you can call a ajax to insert data in the database

Categories

Resources