I'm currently having radio buttons to choose which payment the user want on the website, they can choose between (invoice, card, part payment(?)).
I'm using scripting to submit the radio buttons so no button is needed, however the page reloads every time they choose a different payment option, which is bad for the customer since they have to scroll down again to input the values of the form (phone number etc.) that appear when the radio button is selected.
So after a few complaints I've been trying to fix this issue to make the form appear without the page getting refreshed.
Is it possible to make a few changes in the scripting to make this possible?
Thanks in advance.
Here's the scripting i use:
function autoSubmit(){
var formObject = document.forms['choice_form'];
formObject.submit();
}
Here's the PHP: //I use the post values to show the form where you enter phone number and email
<?php
$value = '';
if(isset($_POST['choice'])) {
$value = $_POST['choice'];
}
?>
Here's the "radio" form:
<form name="choice_form" id="choice_form" method="post">
<table>
<tr>
<td>
<input type="radio" name="choice" <?php if ($value == 'faktura') { ?>checked='checked' <?php } ?> onChange="autoSubmit();" value="faktura"> Faktura
</td>
</tr>
<tr>
<td>
<input type="radio" name="choice" <?php if ($value == 'kort-direkt') { ?>checked='checked' <?php } ?> onChange="autoSubmit();" value="kort-direkt"> Kort / Direktbetalning
</td>
<tr>
<td>
<input type="radio" name="choice" <?php if ($value == 'delbet') { ?>checked='checked' <?php } ?> onChange="autoSubmit();" value="delbet"> Delbetalning
</td>
</tr>
</table>
</form>
If every time a payment option is selected a different form needs to appear underneath the radio buttons, you could render all forms in hidden state in individual <div>s, and then display the corresponding <div> every time an option is selected.
If you need to do something more complex than that, you will probably need to use AJAX.
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 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?
I'm using CakePHP 2.3.8 and I'm trying to create a form with dynamically added inputs from this tutorial but I'm having some issues. The adding and removing of inputs works just fine, but when I submit the form I get a black hole error message. Upon inspecting the inputs, it doesn't appear as if the key value isn't properly set and causing some issues with the id's of the inputs.
For example, with this code in an element
//Elements/users.ctp
$key = isset($key) ? $key : '<%= key %>';
<tr>
<td><?php echo $this->Form->input("Role.{$key}.user_id", array('options' => $users, 'label' => false)); ?></td>
<td class="actions">
Remove User
</td>
</tr>
this is the select that is generated
<select name="data[Role][0][user_id]" id="Role<%=Key%>UserId">
Edit
The value of $key is being set correctly on /Elements/users.ctp. I can create a row and echo the output of $key, and a number for the row appears correctly. As you can see above, the name of the element is set correctly, but the id is still being set strangely.
The name of the select element is being set properly, but not the id.
What is causing the select id to be Role<%=Key%>UserId rather than Role0UserId?
The Problem:
If you observe the generated select tag you posted in question, it shows
<%=Key%>
The variable expected by underscore library utilized by the tutorial you are using is
<%= key %>
CakePHP form input is replacing the html characters and space of that underscore variable, hence its not detectable by underscore library.
The Solution:
In order to fix the issue, you must use plain html code for the template part. Your grades.ctp must be as shown below (partial code for understanding)
<?php if (isset($key)) : ?>
<tr>
<td>
<?php echo $this->Form->input("Grade.{$key}.id") ?>
<?php echo $this->Form->input("Grade.{$key}.subject", array('label' => false)); ?>
</td>
</tr>
...rest of the code
<?php else: ?>
<tr>
<td>
<input type="hidden" id="Grade<%= key %>Id" name="data[Grade][<%= key %>][id]">
<div class="input text required">
<input type="text" required="required" id="Grade<%= key %>Subject" maxlength="200" name="data[Grade][<%= key %>][subject]">
</div>
</td>
...rest of the code
</tr>
<?php endif; ?>
My PHP file echoes results from a data query as a form-table so the user can edit the records. The table will contain up to 30 records. When the form is submitted, if the VoidTag checkbox is selected, I need the user to confirm this action, otherwise the form can submit without the confirm box. I have very little JavaScript experience and have no idea how to do it.
<tr>
<td class="count gridtable">
<input type="text" class="tableTxt" name="inv[1091][Count]"/>
</td>
<td class="count gridtable">
<input type="text" class="count" name="inv[1091][Notes]" value=""/>
</td>
<td class="count gridtable">
<input type="text" class="tableTxt" name="inv[1091][CountedBy]" value=""/>
</td>
<td class="count gridtable">
<input type="checkbox" class="center" name="inv[1091][VoidTag]"/>
<input type="hidden" class="center" name="inv[1091][TagNum]"/>
</td>
</tr>
The other question thread is slightly different, but points you in the right direction, in regards to using a confirmation dialog:
First, I'm assuming that you have a form wrapped around all of these form elements in your table rows . . . you will have to give that form an onsubmit action to return the result of the confirmation function:
<form onSubmit="return confirmSubmit(this);">
Then, use the following function to confirm the submission, based on the presence of any checked checkboxes:
function confirmSubmit(theForm) {
if (theForm.querySelectorAll('input:checked').length > 0) {
return confirm('Do you really want to **insert question criteria here**?')
}
else {
return true;
}
}
When the user submits the form, the code will check to see if there are any "checked" checkboxes in the form (I'm also assuming that there are no other checkboxes or radio buttons in the form, outside of the ones that you want to check in each row). If it finds at least one checked checkbox, it will ask the user to confirm that they want to submit. If they choose "Cancel", it will return false, stopping the form submission . . . in all other cases, it will return true, allowing the submission to continue.
If there ARE other checkboxes or radio buttons in the form, the .querySelectorAll() parameter would need to be changed to accomodate for that, including (potentially) assigning a common class to all of the checkboxes that need to be included in the validation logic.
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;?> />