refresh input field on button click - button

I have this form where the user can insert a quantity in an input field, and see the total in another input field. It works when you insert the numbers manually and I want it to work with buttons too, but i just can't get it to work.
Here's the code:
HTML
<form id="buyForm" method="post" action="cart.php">
<label>Choose quantity</label>
<div>
(+)increase
<input type="text" id="qty1" name="qty[]"/>
(-)decrease
</div>
<input type="text" id="cost1" value="50" style="display:none; visibility:hidden;" name="cost[]" />
<input type="text" id="price1" name="price[]" />
</form>
Js
// Calculate
function calc(idx) {
var price = parseFloat(document.getElementById("cost"+idx).value)*
parseFloat(document.getElementById("qty"+idx).value);
// alert(idx+":"+price);
document.getElementById("price"+idx).value= isNaN(price)?"0.00":price.toFixed(2);
}
window.onload=function() {
document.getElementsByName("qty[]")[0].onkeyup=function() {calc(1)};
document.getElementsByName("cost[]")[0].onkeyup=function() {calc(1)};
}
//Increase/decrease buttons
$(function() {
$(".button").click(function() {
var $button = $(this);
var oldValue = $button.parent().find("input").val();
if ($button.text() == "+") {
var newVal = parseFloat(oldValue) + 1;
// AJAX save would go here
} else {
// Don't allow decrementing below zero
if (oldValue >= 1) {
var newVal = parseFloat(oldValue) - 1;
// AJAX save would go here
}
}
$button.parent().find("input").val(newVal);
});
});
Here it is as jsfiddle: http://jsfiddle.net/rcheH/5/
Can someone please help me with this?
Thanks in advance!

Related

How to create a datepicker search in Dashboard in Angular14?Or, How to filter searchvalues by clicking on Datepicker?

How to create a datepicker search in Dashboard in Angular14? Or, How to filter searchvalues by clicking on Datepicker?
Html:
<input type="date" style="width: 100%; height: 34px" (change)="SendDataonChange($event)"/>
ts:
SendDataonChange(event: any) {
debugger;
clearTimeout(this.timeout);
var $this = this;
this.timeout = setTimeout(function () {
if (event.keyCode != 13) {
$this.applySearchByDateFilter(event.target.value);
}
}, 500);
}
Html:
<input type="date" style="width: 100%; height: 34px" (change)="SendDataonChange($event)"/>
I expect results (dashoard records view) on the basis of clicking A particular date in datepicker
do this work for you?
<input type="date" [ngModel] ="dt | date:'yyyy-MM-dd'" (change)="dt = $event">
Im showing you how you would convert your date to a desirable format (My guess is the format is not right for your service call).
Please let me know if it does not work, i am only answering your question based on my understanding

Wordpress Cookie hidden field

In Wordpress, I try to write o cookie into a hidden field. I have a cookie:
if(isset($_GET['ecselis']))
{
$cookie_name = "ecselis";
$cookie_value = $_GET['ecselis'];
setcookie($cookie_name, $cookie_value, time() + (86400 * 30), "/");
$_SESSION["ecselis"] = $cookie_value;
}
else if(isset($_COOKIE['ecselis'])) {
$_SESSION["ecselis"] = $_COOKIE['ecselis'];
}
else
{
}
This working fine. But I dont realy know how should I write it into a hidden field
<input id="ecselis_field" name="ecselis_field" type="hidden" value="" />
I tried
<input id="ecselis_field" name="ecselis_field" type="hidden" value="$.cookie('ecselis')" />
but it doesn't work at all.
Here is some solution for you, if you want to use js/jquery ( function for getting cookie getCookie() used from this answer ):
function getCookie(name) {
var value = "; " + document.cookie;
var parts = value.split("; " + name + "=");
if (parts.length == 2) return parts.pop().split(";").shift();
}
jQuery(document).ready(function ($) {
$('#ecselis_field').val(getCookie('ecselis'));
})
Add this code into some .js file of your theme/child theme or create your own one.
Tested and works.

check one of the two checkboxes with the same class

I just started using semantic UI and I have a silly question.
I have two checkboxes with class name as "ui toggle checkbox".
When page is loaded, I want to check these checkboxes based on some condition.
<div class="ui toggle checkbox " id="ssl">
<input type="checkbox" name="SSL" >
<label>3</label>
</div>
<br>
<label>Web Service Request Logging : </label>
<div class="ui toggle checkbox" id="wsl">
<input type="checkbox" id="Logging" >
<label>7</label>
</div>
Javascript Code:
$(document).ready(function () {
var wsl = Math.floor((Math.random() * 10) + 1);
var ssl = Math.floor((Math.random() * 10) + 1);
alert(wsl);
alert(ssl);
if (ssl <3) {
$('.ui.toggle.checkbox').checkbox('check');
}
if (wsl <7) {
$('.ui.toggle.checkbox').checkbox('check');
}
});
The problem is, When the number is say 5, it checks both the check boxes. How to differentiate between the two checkboxes with the same class in semanti UI.
Any help will be appreciated.
I would just use the id attribute and get the checkbox input element and toggle the checked attribute with .attr() like:
$(document).ready(function () {
var wsl = Math.floor((Math.random() * 10) + 1);
var ssl = Math.floor((Math.random() * 10) + 1);
alert(wsl);
alert(ssl);
if (ssl <3) {
$('#ssl input:checkbox').attr('checked', true);
}
if (wsl <7) {
$('#wsl input:checkbox').attr('checked', true);
}
});

Get values from two text-box and display sum of that on template in meteor.js

I'm trying to display sum value in template page using meteor.js.
Here is my html code:
<head>
<title>Sum</title>
</head>
<body>
<h1>Sum of two values</h1>
{{> sumForm}}
</body>
<template name="sumForm">
<form>
<input type="text" name="value1"> + <input type="text" name="value2"><p>Total: {{totalSum}}</p>
<input type="submit" value="Sum">
</form>
</template>
and my js code:
if(Meteor.isClient){
Template.sumForm.events({
'submit form': function(event){
event.preventDefault();
value1Var = parseInt(event.target.value1.value);
value2Var = parseInt(event.target.value2.value);
Template.sumForm.totalSum = value1Var + value2Var;
return Template.sumForm.totalSum;
}
});
}
But this does not work.
Can any one help?
You can user reactive-var to achive what you want
First you have to add the lightweight reactive-var package
meteor add reactive-var
Then at your Template file add:
if (Meteor.isClient) {
Template.sumForm.created = function () {
//We set default value
this.counter = new ReactiveVar(0);
}
Template.sumForm.helpers({
totalSum: function () {
return Template.instance().counter.get();
}
});
Template.sumForm.events({
'submit form': function(event, template){
event.preventDefault();
value1Var = parseInt(event.target.value1.value);
value2Var = parseInt(event.target.value2.value);
var sum = value1Var + value2Var;
return template.counter.set(sum);;
}
});
}
Template.sumForm.helpers({
totalSum: function(){
return Session.get("sum");
}
});
And at the end of your submit event
Session.set("sum", value1Var + value2Var);
For a cleaner solution also consider using reactive-var instead of session variables.

Adding conditional CSS classes with ng-class in AngularJS

I have a simple problem. I want to update my classes inside my inputs on form submit.
<div class="form-group">
<input class="form-control" ng-class="{'has-error': signup.$submitted && signup.name.$invalid}" type="text" name="name" ng-model="formData.name" required minlength="2" placeholder="Full Name">
</div>
Here's my app.js:
spinnrApp.controller('FormController', ['$scope', '$http', '$state', function (scope, http, state){
// get list of cities and store it to select
http.get('cities.json').success(function(data){
scope.cities = data;
})
// we will store all our form data in this object
scope.formData = {};
// function to process the form
scope.processForm = function(isValid) {
scope.$submitted = true;
if(isValid && state.$current=='registration.spinnrapp') {
state.go('registration.artist');
} else if(isValid && state.$current=='registration.artist') {
state.go('registration.share');
} else if(!isValid && state.$current=='registration.artist') {
alert('Please make sure you have selected an artist.');
} else if(!isValid && state.$current=='registration.spinnrapp') {
return;
}
};
}]);
When I execute my submit via ng-click calling this function, my signup.$submitted still stays as false. I also have a reference from this Plunker: http://plnkr.co/edit/xDIzC0A50cXxMpIHeP3C?p=preview
That Plunkr updates its class. Why isn't mine doing the same? Am I doing something wrong?

Resources