i have two php file one input page another results page . input page have checkbox. code looks like this
<form action="" id="frmCalculators" method="post" name="frmCalculator">
<input id="chkUFtoLoan-1" name="S" value="S" type="checkbox" checked />
<button id="Button4" type="submit" onclick="GetPage()" class="dont-compare shadow-inset ">
Calculate Scenarios</button>
I have passed check box value next page php
<?php
session_start();
$checkbox1 = $_POST["S"];
?>
i have tired checked using echo value passed in results php.
Now i have question i have value in results page looks like
About your Loan :
<label id="FinancedUpfrontMIP" class="pull-left">Financed Upfront MIP</label>
<label id="financedmip" class="pull-right">$<?php echo round($arrFirstBox["upfrontmipamt"],2);?></label>
Buyer close to section:
<label id="FinancedUpfrontMIP" class="pull-left">Financed Upfront MIP</label>
<label id="financedmip" class="pull-right">$<?php echo round($arrFirstBox["upfrontmipamt"],2);?></label>
my question user select check box value display about your loan if user not select checkbox value display buyer close to section.. Now display same value both place. if one value one show another value need to show Zero.. please any idea about it?
Related
<script>
function refreshPage()
{
document.forms[0].submit();
}
</script>
<?php
foreach($values as $value)
{
?>
<input type = "checkbox" name = "food[]" value = "<?php echo($value['dinner']);?>">
<?php
}
?>
<button name = "pass" onClick = "refreshPage()">refresh</button>
so I have n amount of check box (depending on how many values user has)I want to keep them the check box check after the page refresh (by clicking on refresh button). I tried searching and saw similar form but the answer did not work for me.
For example the most popular answer was:
<input type="checkbox" name="txtCheck" value="your value"
<?php if(isset($_POST['txtCheck']))
echo "checked='checked'"; ?>
/><br />
this had two problem after i hit the refresh button value would not be save until i hit it twice to save(i want it to save after one click. Also sometime it save after one click but if i hit the refresh 3 time values are lost I want it to be save no matter how many time user refresh)
the second problem was it check all of the box would be check. I only want to keep the one user has check to be save.
I looked at various other possible solution but nothing worked
so if you could please help much would be appreciated. Also I need the value to be kept. I am using the checkbox value somewhere else
Edit something like this but for my array food[]. This only works for invidiual values
<input type="checkbox" name="small" class="checkbox" <?php if
($_POST['small']) echo 'checked'; ?> /> Small
I have a form input menu and quantity here (yellow line on pic). When I submit that the data is shown on the table (red line on pic) but is not saved on database (show only). Then I have a save button in the bottom (not yet on the picture because it is cropped) that will store the data that we have input earlier (which appear in the table).
How do I get the input from the menu to only appear in the table but later (after press the save data) is fed into the database?
I'm using CodeIgniter, AJAX and jQuery.
You can use jquery to show input field content in table, here is an example https://jsfiddle.net/y2vmqL06/.
$("input").on('keyup change', function(){
if($(this).val() != ""){
$("#container").text($(this).val());
}else{
$("#container").text("");
}
});
On submit you can use php to do normal database operations
You have to use multiple forms.
After Clicking on submit button in the first form pass your values in the second form and display them and in second form after clicking on save pass them to save into database.
It is just like the procedure mention in the code shown below:
<html>
<form action="yourfilepath.php" method="post">
<input type="text" name="first_value">
<input type="text" name="second_value">
<input type="submit" value="Submit">
</form>
<form action="savedbfile.php" method="post">
<input type="text" name="fst_value" value=" <?php
if(isset($_POST["first_value"]))
echo $_POST["first_value"]);
?> " >
<input type="text" name="sec_value" value=" <?php
if(isset($_POST["second_value"]))
echo $_POST["second_value"]);
?> " >
<input type="submit" value="save">
</form>
</html>
Add data in temporary table first. And after click on save you can move data from temporary table to permanent table.
I have set of check boxes in my Privileges view.
<input type="checkbox" value="1" id="CheckBoxManageDevices"name="CheckBoxManageDevices" />Manage Tracking Devices
<input type="checkbox" value="2" id="CheckBoxMaps" name="CheckBoxMaps" />Manage Maps
I want to save the status of the check boxes (true or false) in the database and load the Privileges page with the updated values in the next time.
I was able to store the status of the check boxes using
$PriviledgeArray["BoxMaps"]=$this->input->post("CheckBoxMaps");
Now I want to fetch check box status to the Privileges page and show the check boxes are marked or unmarked depending on the database value. I have read that java script can be used to solve this but don't have a head start.
Any hint will be highly appreciated.
<?php
$checkedMap="";
$checkedDevices="";
if($CheckBoxMaps==2){ // CheckBoxMaps from database
$checked="checked";
}
if($CheckBoxManageDevices==1){ // CheckBoxManageDevices value from database
$checkedDevices="checked";
}
?>
<input type="checkbox" value="1" id="CheckBoxManageDevices"name="CheckBoxManageDevices" <?php echo $checkedDevices;?> />
<input type="checkbox" value="2" id="CheckBoxMaps" name="CheckBoxMaps" <?php echo $checkedMap;?> />
I need to create a system to print information about items in a database. By now I have an html form with several input fields (types = text and radio), so I can collect all the info of an item.
To make the process faster I introduce a javascript to duplicate the whole empty form 'n' times with a click, so one can print several items information at once. My script looks like this:
<body>
<button id="button" onclick="duplicate()">add form</button><!--this button duplicates the empty form-->
<form action="action.php" method="post" name="formulario">
<div id="duplicater">
<p>Código:<input type="text" name="codigo" /></p>
<p>Nombre del proyecto:<input type="text" name="proyecto" /></p>
<p>
<span>
<input type="radio" name="grupo1" value="SD" />SD
<input type="radio" name="grupo1" value="HD" />HD
</span>
<span>
<input type="radio" name="grupo2" value="4:3"/>4:3
<input type="radio" name="grupo2" value="16:9"/>16:9
</span>
</p>
<p>Fecha:<input type="text" name="fecha" /></p>
<p>Lugar:<input type="text" name="lugar" /></p>
<p>Dueño:<input type="text" name="dueno" /></p>
</div>
<p><input type="submit" name="submit" value="enviar" /></p>
</form>
<script>
document.getElementById('button').onclick = duplicate;
var i = 0;
var original = document.getElementById('duplicater');
function duplicate() {
var clone = original.cloneNode(true); // "deep" clone
clone.id = "duplicator" + ++i; // there can only be one element with an ID
original.parentNode.appendChild(clone);
}
</script>
</body>
At this point, this part of the project is working fine, but I have a problem with the action.php file that handle the functionality to send the information from all the forms to a new page to print it.
The action.php collects the information of the form using the name attribute of every input. As every form is just a duplicate of the original one, every new form have the same name attribute, so when I click the send button, the php just echo the information of the last form.
<div><span>Código: </span><?php echo htmlspecialchars($_POST['codigo']); ?></div>
<div><span>Proyecto: </span><?php echo htmlspecialchars($_POST['proyecto']); ?></div>
<div><span>Calidad: </span><?php echo htmlspecialchars($_POST['grupo1']); ?></div>
<div><span>Formato: </span><?php echo htmlspecialchars($_POST['grupo2']); ?></div>
<div><span>Fecha: </span><?php echo htmlspecialchars($_POST['fecha']); ?></div>
<div><span>Lugar: </span><?php echo htmlspecialchars($_POST['lugar']); ?></div>
<div><span>Dueño: </span><?php echo htmlspecialchars($_POST['dueno']); ?></div>
Questions:
I need to update (rename) the name attribute of the input tags in every duplicated form, how can I do that?
It is possible to refer the echo function in the action.php file to a div with an id assigned to post the whole information at once? otherwise, how can I send (post) the information of all the duplicated form to a new page at once?
This have to be a client side process, so there is nothing more behind it, the php is just for echoing the info to the new page. So if there are solutions that can be done with javascript or jQuery is ok as well.
I leave a link to the demo http://www.programaicat.una.ac.cr/ICATsite/demo/
Thanks to all in advance.
The way POST vars are sent to a script, they're named key, value pairs in an array. Any inputs with the same name will be overwritten.
I suggest appending or prepending a number to each additional input as they are created, so instead of a new input called "name", it would be called "name.1" or "1.name". Your first input would be "name.0" and the rest would increment upwards as they are added. When you process the information, you can iterate over the POST array keys using substr and re-shape your information as needed before saving it to the database.
First of, I'm new to ajax and Java Script.. I have spend days solving this problem, but I still haven't figured it out. I have read through threads with similar problems but I still can't get it right. So here goes;
Quite simple I want post the checked value from from one of three radio buttons. All I get though is only the value of the first radio button..
I have tried several things, but I stripped down the code so it might be easier see where the problem is :-)
The ajax
<script type"text="" javascript"="">
$(document).ready(function(){
$("form#submit").submit(function() {
// we want to store the values from the form input box, then send via ajax below
var svar = $('#svar').attr('value');
var date = $('#date').attr('value');
var email = $('#email').attr('value');
$.ajax({
type: "POST",
url: "ajax.php",
data: "svar="+ svar + "&email=" + email + "&date=" + date,
success: function(){
$('form#submit').hide();
//$('form#submit :input').val("");
$('div.success').fadeIn();
}
});
return false;
});
});
</script>
The form
<form id="submit" method="post" name="submit" action="">
<fieldset>
<legend>Dagens spørgsmål: <? echo $row['question'];?></legend>
<br>
<input type="radio" name="svar" id="svar" value="1"><? echo $row['opt1'];?>
<br>
<input type="radio" name="svar" id="svar" value="2"><? echo $row['opt2'];?>
<br>
<input type="radio" name="svar" id="svar" value="3"><? echo $row['opt3'];?>
<br>
<input name="email" id="email" type="hidden" value="<? echo $email ?>" />
<input name="date" id="date" type="hidden" value="<? echo $date ?>" />
<br><br>
<button type="submit" class="button positive"> <img src="img/tick.png" alt=""> Svar på dagens spørgsmål </button>
</fieldset>
</form>
Ajax.php
<?php
include ("dbc.php");
// CLIENT INFORMATION
$email = htmlspecialchars(trim($_POST['email']));
$date = htmlspecialchars(trim($_POST['date']));
$svar = htmlspecialchars(trim($_POST['svar']));
//stuff from answers
mysql_query("INSERT INTO answers
(`email`,`day`,`answer`)
VALUES
('$email','$date','$svar')") or die(mysql_error());
?>
Hope one you of you smart guys have a solution.. because this thing i driving me crazy
You have several problems.
First, your HTML is invalid. An ID must be unique, so each radio button must have its own ID. You associate a group of radio buttons by giving them the same NAME. (Having a unique ID then lets you associate a LABEL with each one using the FOR attribute which increases accessibility by making it easier for screen readers and providing bigger click targets).
Second, the value of a radio button is fixed. The question is "Is it successful or not?" and that is determined by seeing if it is checked or not. If you were doing this manually, you would have to loop over each radio button in the group until you found one that was checked (or use a selector that matched only the checked ratio button (:checked)).
Third, you are building your form data by mashing together strings without making sure the data is URL safe (with encodeURIComponent).
The solution is to forget about doing all this manually and just use the jQuery serialize method on the form.
First: you use the same id for several elements. ID-s should be unique, and you should address your elements with class name or other means. So instead of
$('#svar')
yous should use
$('input[name=svar]')
to reference the group of checkboxes.
Second: There is a slight mistake here:
$('#svar').attr('value');
is the value of the first radio button's value attribute, while
$('input[name=svar]:checked').val();
would give you the value of the checked radio button in the group you are selecting with input[name=svar].
Edit: thx #Quentin for pointing out my error.
First thing to know is id should be unique in a html document.
What makes attributes of type ID special is that no two such
attributes can have the same value;
[Quoted from css2 selector docs]
You have assigend same id to three radio buttons.
Now when you use var svar = $('#svar').attr('value');, only the first radio button will get selected. So, irrespective of radio button selected, only the first radio buttons value you will get.
Now, if you want to get the radio button selected you have to use jQuerys :checked selector.