I have a counter which adds number of rows to a table based on what the counter is. I have one button that increase the counter every time its clicked, but it only works one time.
php:
if (isset($_REQUEST['Addmore'])) {
$NoOfUsers++;
<form action="addstudent.php">
<th>
<button type="submit" class="btn btn-default btn-sm spoiler-trigger pull-right" aria-label="Left Align" name="Addmore" title="Add Row">
<span class="glyphicon glyphicon-thumbs-up" aria-hidden="true"> </span>
</button>
</th>
</form>
php
<?php
session_start();
if (isset($_REQUEST['Addmore'])) {
?><button class="btn btn-default"><?php
echo $_SESSION['NoOfUsers'] ? ++$_SESSION['NoOfUsers'] : $_SESSION['NoOfUsers']=1;
?></button><?php
}
or JavaScript
<button id="counter" class="btn btn-default">0</button>
<script>
$('#counter').on('click',function(){$( this ).html(1 * $( this ).html() + 1)});
</script>
Related
I'm just gonna ask what's the best way to do Increase the number of items if it's out of stock or below 100.
Like Medicine is 95 and you input 5 then click add button then the result will be 100.
<td>{{ $medicine->medicine_qty }}
<input style="width: 50px;" class="box" type="number" id="qty">
<button type="submit" class="btn btn-secondary" data-dismiss="modal" id="addMed">Add</button>
<button type="submit" class="btn btn-secondary" data-dismiss="modal" id="minusMed">Minus</button>
</td>
In front end you can add name tag in your buttons and in backend have a code something like this:
<td>{{ $medicine->medicine_qty }}
<input style="width: 50px;" class="box" type="number" id="qty" name="qty">
<button type="submit" class="btn btn-secondary" data-dismiss="modal" id="addMed" name="addMed">Add</button>
<button type="submit" class="btn btn-secondary" data-dismiss="modal" id="minusMed" name="minusMed">Minus</button>
</td>
$qty = $request->get('qty');
if($request->get('addMed')){
// add value to your medicine
$yourModelValue += $qty;
} elseif($request->get(''){
// remove value from medicine
$yourModelValue -= $qty;
}
You will need to submit a request if you want to update the data. If you want a button press to trigger it without leaving or refreshing the page, then you'll probably want to make an AJAX request and have it update the value in the database, then return the new value you will want to reflect on the page.
i have 5 divs , with different id's. I want to make a step formation like if i get the value(from url) measures
example:
, it shows me the first div with id measures and rearrange the rest of the divs including fabrics which exists before measures div and so on
Then after, when i click the Next button it shows me the rearranged div one by one.
I have done this whole code using php and jquery.
Is it possible to do this using jquery or javascript or anything, Please help me to fix this.
Thanks in advance.
my Code is
var navListItems = $('div.setup-panel div a'),
allWells = $('.setup-content'),
allNextBtn = $('.nextBtn'),
allPrevBtn = $('.prevBtn');
allWells.hide();
navListItems.click(function (e) {
e.preventDefault();
var $target = $($(this).attr('href')),
$item = $(this);
if (!$item.hasClass('disabled')) {
navListItems.removeClass('btn-primary').addClass('btn-success');
$item.addClass('btn-primary');
allWells.hide();
$target.show();
$target.find('input:eq(0)').focus();
}
});
allPrevBtn.click(function(){
var curStep = $(this).closest(".setup-content"),
curStepBtn = curStep.attr("id"),
prevStepWizard = $('div.setup-panel div a[href="#' + curStepBtn + '"]').parent().prev().children("a");
prevStepWizard.removeAttr('disabled').trigger('click');
});
allNextBtn.click(function(){
var curStep = $(this).closest(".setup-content"),
curStepBtn = curStep.attr("id"),
nextStepWizard = $('div.setup-panel div a[href="#' + curStepBtn + '"]').parent().next().children("a"),
curInputs = curStep.find("input[type='text'],input[type='url']"),
isValid = permission;
$(".form-group").removeClass("has-error");
for(var i=0; i<curInputs.length; i++){
if (!curInputs[i].validity.valid){
isValid = false;
$(curInputs[i]).closest(".form-group").addClass("has-error");
}
}
if (isValid)
nextStepWizard.removeAttr('disabled').trigger('click');
});
$('div.setup-panel div a.btn-primary').trigger('click');
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div class="row setup-content" id="step-1"> // i will change it's id to fabrics
<button class="btn btn-primary nextBtn btn-lg pull-right btn-xs fabric_button" id="fabric"> Next </button>
</div>
<div class="row setup-content" id="step-2" > // i will change it's id to patterns
<button class="btn btn-primary nextBtn btn-lg pull-right btn-xs" type="button" id="pattern" >Next</button>
</div>
<div class="row setup-content" id="step-3" > // i will change it's id to measures
<button class="btn btn-primary nextBtn btn-lg pull-right btn-xs" type="button" id="pattern" >Next</button>
</div>
<div class="row setup-content" id="step-4" > // i will change it's id to Pair
<button class="btn btn-primary nextBtn btn-lg pull-right btn-xs" type="button" id="pattern" >Next</button>
</div>
<div class="row setup-content" id="step-5" > // i will change it's id to total
<button class="btn btn-primary nextBtn btn-lg pull-right btn-xs" type="button" id="pattern" >Next</button>
</div>
I'm working on a web page where a user will be allowed to add or edit a feedback for a place. If the person already gave the place a feedback, he/she will be shown an Edit Review button otherwise, the user will be shown an Add Review button.
In my feedback table in my database, I have a places_id and users_id column. Here's my query in PHP (Assuming that $id and $places_id have values):
<?php
$query5 = mysql_query("SELECT * FROM feedback WHERE user_id = '$id' AND places_id = '$places_id'");
$row5 = mysql_fetch_array($query5);
if($row5['user_id'] != $id){
?>
<button type="button" class="btn btn-default"><span class="glyphicon glyphicon-arrow-left"></span> Back</button>
<button class="btn btn-primary" type="submit" name="submit">Review</button>
<?php }else{ ?>
<button type="button" class="btn btn-default"><span class="glyphicon glyphicon-arrow-left"></span> Back</button>
<button class="btn btn-primary" type="submit" name="submit">Edit Review</button>
<?php } ?>
I was thinking that if the query did not return a result where the given user_id is not equal to the user_id in the result, it would let me do my if-else condition. However if there is a feedback for a current place, it displays the button found in the else statement.
What do you think is the problem and why is the if condition not working?
I also tried if(mysql_num_rows($query5)==0) but it's also not working.
I would always do:
<?php
$query5 = mysql_query("SELECT * FROM feedback WHERE user_id = '$id' AND places_id = '$places_id'");
if ($row5 = mysql_fetch_array($query5)) {
?>
<button type="button" class="btn btn-default"><span class="glyphicon glyphicon-arrow-left"></span> Back</button>
<button class="btn btn-primary" type="submit" name="submit">Edit Review</button>
<?php }else{ ?>
<button type="button" class="btn btn-default"><span class="glyphicon glyphicon-arrow-left"></span> Back</button>
<button class="btn btn-primary" type="submit" name="submit">Review</button>
<?php } ?>
I have the following code=>
<button class="btn btn-lg btn-warning text-center but-width" id="first" name="geri" type="submit" value="<?php ?>">BACK</button>
<button class="btn btn-lg btn-warning text-center but-width" id="second" name="ileri" type="submit" value="<?php ?>">FORWARD</button>
These buttons submit the form to the same page. At the top of the page I have variable $t which is initialized at value '0' and is followed by the codes=>
$t=0;
if( $this->input->post('ileri') ) { $t=$t+1;} // Back button was pressed;
if( $this->input->post('geri') ) { $t=$t-1;} // Forward button was pressed;
Now as I press forward I want to increase $t and when I press back I want to decrease it. But because of the declaration at the top ($t=0;) it goes as far as '1' with 'forward' and as back as '0' with 'back' buttons. Can anyone think of a way of getting over this problem.
Thank you...
Add a hidden input, and store $t there. This gets posted upon submit:
<?php
$t = $this->input->post('t');
if (!$t) $t = 0;
if( $this->input->post('ileri') ) { $t=$t+1;} // Back button was pressed;
if( $this->input->post('geri') ) { $t=$t-1;} // Forward button was pressed;
?>
<input name="t" type="hidden" value="<?=$t ?>">
<button class="btn btn-lg btn-warning text-center but-width" id="first" name="geri" type="submit" value="submit">BACK</button>
<button class="btn btn-lg btn-warning text-center but-width" id="second" name="ileri" type="submit" value="submit">FORWARD</button>
You could use url parameter. Get instead of post. so that it stores the current value of variable $t i.e.
if (isset($_GET['t']))
{
$t = $_GET['t'];
}
else
{
$t = 0;
}
Something like that could be of some help
If you want to know what button makes the submit you need to change the buttons
<button class="btn btn-lg btn-warning text-center but-width" id="first" name="geri" type="submit" value="<?php ?>">BACK</button>
<button class="btn btn-lg btn-warning text-center but-width" id="second" name="ileri" type="submit" value="<?php ?>">FORWARD</button>
to
<button class="btn btn-lg btn-warning text-center but-width" id="first" name="s_button" type="submit" value="geri">BACK</button>
<button class="btn btn-lg btn-warning text-center but-width" id="second" name="s_button" type="submit" value="ileri">FORWARD</button>
in your controller
$button_s = $this->input->post('s_button');
if( isset($button_s)){
switch($button_s){
case 'geri':
//do somthing
break;
case 'ileri':
//do somthing
break;
}
}
i have two buttons of type submit in my view:
<button type="submit" class="btn btn-default btn-xs" name="Excel">
<span class="glyphicon glyphicon-download-alt"></span> Download as Excel
</button>
<button type="submit" class="btn btn-default btn-xs" name="Resume">
<span class="glyphicon glyphicon-download-alt"></span> Download Resume
</button>
and controller:
if ($this->input->post('Resume')) {
echo "Resume Clicked";
}
if ($this->input->post('Excel')) {
echo "Excel Clicked";
}
i would like to know that which button has submitted the form for that i have written the above code..but i am not getting any echo after clicking any of the button..
i don't want to use here:
<input type='submit' name='excel' value='Excel'/>
<input type='submit' name='excel' value='Excel'/>
as it works with the type 'input' i would like to use button of type submit
Add a value to the button, ie:
<button type="submit" class="btn btn-default btn-xs" name="Resume" value="true">
<span class="glyphicon glyphicon-download-alt"></span> Download Resume
</button>
You will have a $_POST['Resume'] with value "true" in your backend code.
Ofcourse something like: name="buttonName" value="Excel" and another button with name="buttonName" value="Resume" would make have a $_POST['buttonName'] with its value either being 'Excel' or 'Resume'.