Click button A submit button B at the same time - javascript

I want to auto calculate shipping when the quantity changed?
How can "Calculate shipping botton" auto submit when updated quantity?
This script worked in the first time when i clicked to quantity button, it do not work in the next time. I appreciate your help!
<button class="quantity__button" name="minus" type="button">Minus</button>
<button class="quantity__button" name="plus" type="button">Plus</button>
<input type="button" class="get-rates" value="CALCULATE SHIPPING" />
<script>
$('.quantity__button').click(function(){
$('.get-rates').click();
})
</script>

Related

Don't hide date on button click when page refresh

I want to print the date when last time clicked on a button. It's actually working, but it's gone on page refresh but I don't want to hide it. How can I do it?
<input onclick="document.getElementById('demo').innerHTML=Date()" type="submit" name="Button" value="Button" />
<p id="demo"></p>
i hope this will work, you can check the codepen date and time of button clicked after clicking the button just refresh you will get the new date and time.
function storeDate() {
var currentDate = Date();
localStorage.setItem("dateofButton", currentDate)
}
(function(){
if(localStorage.dateofButton){
document.getElementById('demo').innerHTML = localStorage.dateofButton
}else{
// its empty
}
})()
<input onclick="storeDate()" type="submit" name="Button" value="Button" />
<p id="demo"></p>
You seem to have this at the end of a Form, so using the type submit submits the parent form, resulting in either a reload or a being redirected to the website specified in the action attribute of the form.
Either remove the type="submit" and make it a type="button" or return false from the onclick handler:
Input type button:
<input onclick="document.getElementById('demo').innerHTML=Date()" type="button" name="Button" value="Button" />
<p id="demo"></p>
Returning false:
<form action="something">
<input onclick="document.getElementById('demo').innerHTML=Date(); return false;" type="button" name="Button" value="Button" />
</form>
<p id="demo"></p>
The solution with localStorage, mentioned in comments, would look like this:
$(function() {
$("#demo").innerHTML = localStorage.date;
});
$("#buttonId").click(function() {
localStorage.date = Date();
});

Breadcrumb menu update on button click?

Currently, this is all I have in terms of code for this:
1 >
This <a> link will probably need some changes, since ideally the user could click on the number and revert to that question number.
and 2 buttons
<input class="btn btn-success NavigationButtons" id="BackButton" type="submit" name="Previous" value="Back" />
<input class="btn btn-success NavigationButtons" id="ForwardButton" type="submit" name="NextPage" value="#Session["ForwardButtonText"]" onclick="RadBtnValidation()"/>
So what I need, is every time the user clicks the button with id="ForwardButton" is for the 1 > to change to 1 > 2 > and vice versa whe the user clicks the back button. Thanks in advance
You can store numbers and append they inside a every button click.
var numberList = [];
init();
function init(){
numberList.push(1);
ShowNumber();
}
$("#BackButton").click(function(){
numberList.pop();
ShowNumber();
});
$("#ForwardButton").click(function(){
numberList.push(numberList[numberList.length-1] + 1);
ShowNumber();
});
function ShowNumber(){
$("#txtPageNumber").html("");
for(var i=0; i<numberList.length;i++)
{
$("#txtPageNumber").append(numberList[i] + ">");
}
}
https://jsfiddle.net/gnne36nw/1/

AJAX, JQuery, calculate price after button click

I want to calculate the price after a button click.
I have 3 buttons which are selectable.
For example : button1 = 50$, button2 = 100$, button3 = 200$
Now I want to update the price after a button click.
Is there any solution to handle this? Because, If i send the Ajax request and update my html-element the price isn't added. My old price always disappear.
So if the user selects button1 the price is 50$, but if the user also selects button2 my price is 100$, not $150.
Thanks :)
Here is the idea:
<script>
function add(x) {
document.getElementById('result').innerText = +(document.getElementById('result').innerText) + x;
}
</script>
<form>
<input type="button" onclick="add(50)" value="50">
<input type="button" onclick="add(100)" value="100">
<input type="button" onclick="add(200)" value="200">
</form>
<div id='result'></div>
Note: +(x) forces conversion of x to number

Why does the value is displayed and then disappear after I click on the button in JavaScript?

Whenever I click on the button I get the output for a second in the text-field "Result" and then it's gone.. why does it disappear? (I have tried to place the function in the body.. it doesn't help..)
<html>
<head>
<script>
function someFunction()
{
with (document.formy)
{
resultsBox.value= "In " + yearsBox.value + "you will be" + ageBox.value + yearsBox.value +" years old.";
}
}
</script>
</head>
<body>
<form name="formy">
Enter your current age: <input id="ageBox" type="text" value="18" />
<br/>
Enter number of years: <input id="yearsBox" type="text" value="5" />
<br/>
Click this button: <button onclick="someFunction()">Click me! </button>
<br/>
Results: <input id="resultsBox" type="text" />
</form>
</body>
</html>
The default type for buttons is submit. When you click the button the form is submitting and reloading the page. You can avoid this by setting the type attribute on the button:
<button type="button" onclick="someFunction()">Click me!</button>
Add an attribute to your form button called type. Specifically, something like:
type="button"
The reason is the default behavior of a button within a form is to act as a submit button. Submitting, results in the page being reloaded and thus the text field is cleared.
That submits the form & reloads, to prevent it:
onclick="someFunction(); return false;">
Also you should avoid with().

change form element before submit with javascript

In the below code I am able to get the alert message to display correctly displaying the message and the number "3". Does anyone know how to use that passes variable/number to declare a form element named "priority" to be passed to the form before submitting?
My goal is to use $_POST["priority"] and generate the number 1, 2, or three based on which link/button is clicked.
<script language="JavaScript">
function submitForm(priority)
{
alert("Changing to Priority " + priority);
document.frm.submit();
}
</script>
<span class="label">Low</span>
<span class="label">Medium</span>
<span class="label">High</span>
Add a hidden field in the form:
<input id='priority' name='priority' type='hidden'/>
Before the last form submit call, add something like this:
document.getElementById('priority').value = priority;
You don't need any script, use 3 submit buttons:
<button type="submit" name="priority" value="1">Priority 1</button>
<button type="submit" name="priority" value="2">Priority 2</button>
<button type="submit" name="priority" value="3">Priority 3</button>
Only the one that is clicked will send it's value to the server.

Categories

Resources