i have this code:
Amount<input type='text' name='amount' size='10' >
<br>
Free<input type='text' name='fees' size='10' >
<br>
------------
<br>
<input type='radio' name='amount_type' value='Receive'checked> Receive<br>
<input type='radio' name='amount_type' value='Send'> Send<br>
-------------
<br>
<input type='radio' name='curr' value='LBP'checked> LBP<br>
<input type='radio' name='curr' value='USD'> USD<br>
what i want to do is
if amount more than 5000 , check radio button curr : value LBP else check usd
if fees are inserted , in radio button amount_type : check Receive else check send.
can you assist please
Use this code.
Amount<input type='text' name='amount' size='10' id='amount' >
<br>
Free<input type='text' name='fees' size='10' id='fees' >
<br>
------------
<br>
<input type='radio' id='receive' name='amount_type' value='Receive'checked> Receive<br>
<input type='radio' id='send' name='amount_type' value='Send'> Send<br>
-------------
<br>
<input type='radio' id='lbp' name='curr' value='LBP'checked> LBP<br>
<input type='radio' id='usd' name='curr' value='USD'> USD<br>
jquery
<script src="https://code.jquery.com/jquery-1.12.4.min.js"></script>
<script>
$(document).ready(function(){
$("#usd").prop("checked", true);
$("#send").prop("checked", true);
$("#amount").on("input", function(){
// Print entered value in a div box
if($("#amount").val() > 5000){
$("#lbp").prop("checked", true);
}else{
$("#usd").prop("checked", true);
}
});
$("#fees").on("input", function(){
// Print entered value in a div box
if($("#fees").val() > 0){
$("#receive").prop("checked", true);
}else{
$("#send").prop("checked", true);
}
});
});
</script>
check out online demo : DEMO
Related
See question -
I've tried this:
echo "<form action='index.php' method='post'>
Use the previous input of participants: <input type='radio' name='participants[]'value='$participants[0]'>
OR <br>
<form action='index.html' method='post'>
Use a different input of participants: <input type='radio' name='participants[]' value='0'>
<input type='submit' value='send' name='send'> </form> <br>";
Both of the radio button lead me to index.php when I want to be able to go to index.html in case i press on the second radio button.
You may solve it by using JQuery
<form action='index.php' method='post'>
Use the previous input of participants:
<input type='radio' name='participants[]' value='$participants[0]'>
<br/>OR <br>
Use a different input of participants:
<input type='radio' name='participants[]' value='0'>
<input type='submit' value='send' name='send'>
</form>
<script src="//ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script>
$(document).ready(function(){
var form = $('form');
var input = $('input[type=radio]');
input.on('click', function() {
if ($(this).val()==0) {
form.prop('action', 'index.html');
} else {
form.prop('action', 'index.php');
}
});
});
</script>
I am working on basic functionality of insert,add,delete and update using ajax.
I have done little functionality write now..actually i want all functionality in a grid .
I put all html code inside a for loop.. this loop will execute till total num rows.. first execution of loop is fine, problem occur after this... next time when i click on delete button ajax call is not working.
Need help on this....
I have 2 files.. form.php and operation.php
code of form.php..
$(document).ready(function(){
$("#delete").click(function(){
var id=$("#uid").val();
$.post("operation.php",{ID:id},function(data){
$("#result").html(data);
});
});
});
for($i=0;$i<2;$i++)
{
echo "<input type='text' value=".mysql_result($all_records, $i, "id")." name='uid' id='uid'>
<input type='text' value=".mysql_result($all_records, $i,"name")." name='name' id='email' placeholder='Email'>
<input type='text' value=".mysql_result($all_records, $i,"email")." name='email' id='email' placeholder='Email'>
<input type='password' value=".mysql_result($all_records, $i,"password")." name='pass' id='pass' placeholder='Password'>
<input type='submit'name='delete' id='delete' value='Delete'>
<input type='submit'name='update' id='update' value='Update'>";
echo "</td></tr>";
}
operation.php
write now i put only one line code for checking purpose...
echo $_POST['ID'];
Well i think you know that ids should have unique names. It is not a good idea to give same id to multiple elements in the same page.
I think the code bellow will solve your purpose.
$(document).ready(function(){
$(".delete").click(function(){
var id=$(this).data('id');
$.post("operation.php",{ID:id},function(data){
$("#result").html(data);
});
});
});
for($i=0; $i<2; $i++)
{
echo "<input type='text' value='".mysql_result($all_records, $i, "id")."' name='uid' class='uid'>
<input type='text' value='".mysql_result($all_records, $i,"name")."' name='name' class='name' placeholder='Email'>
<input type='text' value='".mysql_result($all_records, $i,"email")."' name='email' class='email' placeholder='Email'>
<input type='password' value='".mysql_result($all_records, $i,"password")."' name='pass' class='pass' placeholder='Password'>
<input type='button'name='delete' data-id='".mysql_result($all_records, $i, "id")."' class='delete' value='Delete'>
<input type='submit' name='update' class='update' value='Update'>";
echo "</td></tr>";
}
Try to understand it and compare it with your previous code.
Let me know if you need further assistance.
I'm making a Quiz. And with each question I'm showing the possible answers( "True" or "False") with a While loop in PHP:
echo "<form method='post' action='quizCheck.php'>";
while(x=0;x<=10; x++){
echo "<div class='buttons'>
<label>True
<input type='radio' name='answer' value='true' />
</label>
<label>False
<input type='radio' name='answer' value='false' />
</label>
</div>";
}
echo "</form>";
Let's say there are 10 questions and I select "True" on 6 questions.
What code do I have to put in quizCheck.php so it can count the number of "True" answers and store it in a variable?
You will need to do two things, first you need a submit button in the form:
<button type="submit" value="Submit">Submit</button>
Then you will also need the names of the radio inputs to be unique so in the while loop (which you really should just change to a for loop) do:
for(x=0;x<=10; x++){
echo "<div class='buttons'>
<label>True
<input type='radio' name='answer{$x}' value='true' />
</label>
<label>False
<input type='radio' name='answer{$x}' value='false' />
</label>
</div>";
}
When the form is submitted, then in quizCheck.php you just check $_POST[answer0] through $_POST[answer9] to see which are true and increment a counter.
If you want the answers in a single array then do this:
for(x=0;x<=10; x++){
echo "<div class='buttons'>
<label>True
<input type='radio' name='answers[$x]' value='true' />
</label>
<label>False
<input type='radio' name='answers[$x]' value='false' />
</label>
</div>";
}
When this form is submitted, then in quizCheck.php you just get something like $answers = $_POST[answers] and then go through answers[0] to answers[9] for example
I am having a bit of troubles submitting my form with jQuery..
I got this:
<div class='widget-body'>
<div class='center' id='formHolder' style='display:none'>
<div id='amountDiv'>$<span id='amountSpan'></span></div>
<div class='pagination pagination-centered margin-none' style='font-size:15px;'>
<ul>
<li><a href='javascript:void(0)' id='dec'>-</a></li>
<li class='active'><a href='javascript:void(0)' class='addfunds'>Add Funds</a></li>
<li><a href='javascript:void(0)' id='inc'>+</a></li>
</ul>
</div><!--//Pagination-->";
$contents .= "
<form action=\"https://www.paypal.com/cgi-bin/webscr\" method=\"post\" id=\"ppform\">
<input type=\"hidden\" name=\"cmd\" value=\"_xclick\" />
<input type=\"hidden\" name=\"business\" value=\"{$set['pp_paymentemail']}\" />
<input type=\"hidden\" name=\"quantity\" value=\"1\" />
<input type=\"hidden\" name=\"item_name\" value=\"{$set['rbalanceadd_paymenttext']}\" />
<input type=\"hidden\" name=\"amount\" class='a' value=\"\" />
<input type=\"hidden\" name=\"item_number\" value=\"{$ir['username']}\" />
<input type=\"hidden\" name=\"no_shipping\" value=\"1\" />
<input type=\"hidden\" name=\"return\" value=\"$return\" />
<input type=\"hidden\" name=\"currency_code\" value=\"{$set['currency_type']}\" /></form>
<form method=\"post\" action=\"https://secure.payza.com/checkout\" id='pzform' />
<input type=\"hidden\" name=\"ap_purchasetype\" value=\"service\" />
<input type=\"hidden\" name=\"ap_merchant\" value=\"{$set['ap_paymentemail']}\" />
<input type=\"hidden\" name=\"ap_itemname\" value=\"{$set['rbalanceadd_paymenttext']}\" />
<input type=\"hidden\" name=\"ap_currency\" value=\"{$set['currency_type']}\" />
<input type=\"hidden\" name=\"ap_returnurl\" value=\"{$myi}\" />
<input type=\"hidden\" name=\"ap_quantity\" value=\"1\" />
<input type=\"hidden\" name=\"ap_amount\" class='a' value=\"\" />
<input type=\"hidden\" name=\"ap_description\" value=\"{$ir['username']}\" />
</form>
";
$contents.="
</div><!--//formHolder-->
<div id='btHolder'>
<div class='center'>
<img src='themes/steel/theme/images/icons/paypal.png' style='margin-left:10px;margin-right:10px;' id='paypalBt'>
<img src='themes/steel/theme/images/icons/payza.png' id='payzaBt'>
</div><!--//Center-->
<br />
</div><!--//btHolder-->
</div><!--//Widget Body-->
So, first off all the user is choosing his/her payment method. That is done by either choosing #payzaBt or #paypalBt
After that, the user must specify how much money he/she wishes to add.
That is done with #inc or #dec (This will add the amount to the amount input field of both the PayPal and Payza form.
My jQuery looks like this:
$(document).ready(function() {
$('#paypalBt').click(function() {
$('.addfunds').attr('id','addfundspp');
$('#btHolder').hide();
$('#formHolder').show();
});
$('#payzaBt').click(function() {
$('.addfunds').attr('id','addfundspz');
$('#btHolder').hide();
$('#formHolder').show();
});
$('#addfundspz').click(function() {
$('#pzform').submit();
});
$('#addfundspp').click(function() {
$('#ppform').submit();
});
$('#amountSpan').text('5');
$('.a').val('5');
$('#inc').click(function(){
$('#amountSpan').text( Math.min(100, Number($('#amountSpan').text()) + 5) )
$('.a').val( Math.min(100, Number($('.a').val()) + 5) )
});
$('#dec').click(function(){
$('#amountSpan').text( Math.max(5, Number($('#amountSpan').text()) - 5) )
$('.a').val( Math.max(5, Number($('.a').val()) - 5) )
});
});
Now all of this works fine. The problem is when the user must submit the PayPal or the Payza form. As you can see in the above jQuery code I am first adding an ID attribute to the "Add Funds" button; when that button is clicked, I am using the jQuery submit form function. But this doesn't work. No form is submitted.
What is wrong?
Thanks in advance.
That is because #addfundspz (and #addfundspp) doesn't exist when document is ready
You can use event delegation
$(document).on('click','#addfundspz',function() {
$('#pzform').submit();
});
http://learn.jquery.com/events/event-delegation/
here is my code, hope you all can understand.
[html form coding]
<form method='post' action='pro/handle.php'><br/>
<input type='text' name='FirstTXT' value='First'>
<button type='button' name='ADDINPUT'>add</button>
<div id='SETSET'>
<!-- prepare for adding input element by using jquery -->
</div>
<input type='text' name='LastTXT' value='Last'>
<button type='submit' name='BTN' value='Submit'>submit</button>
</form>
[Jquery coding]
$(document).on("click","[name=ADDINPUT]",function(){
var inp = "<input type='text' name='ADDTXT'>";
$("#SETSET").append(inp);
});
So far NO error/problem for the code above(tested), jquery input did append into #SETSET accordingly.[The problem is]
after click on form [submit] button, php NOT able to get the element of [ADDTXT]when i use php to loop & get everything from previous page, result as below:-
[PHP coding]
foreach($_post as $key=>$val){
echo "<br/>$key : $val";
}
[Result]
FirstTXT : First<br/>
LastTXT : Last<br/>
BTN : Submit<br/>
//=== Missing ADDTXT (between First & Last)===//
Did you guys/gals know why?
Maybe that:
html:
<form method='post' action='pro/handle.php'><br/>
<input type='text' name='FirstTXT' value='First'>
<button type='button' name='ADDINPUT'>add</button>
<div id='SETSET' style='display: none;'>
<!-- prepare for adding input element by using jquery -->
<input type='text' id='ADDTXT' name='ADDTXT' disabled='disabled'>
</div>
<input type='text' name='LastTXT' value='Last'>
<button type='submit' name='BTN' value='Submit'>submit</button>
</form>
and JS:
$(document).on("click","[name=ADDINPUT]",function(){
$("#SETSET").show();
$("#ADDTXT").removeAttr("disabled");
});
You have an array from that field.
Replace:
var inp = "<input type='text' name='ADDTXT'>";
With:
var inp = "<input type='text' name='ADDTXT[]'>";
And PHP:
if(is_array($val)) { print_r($val); }
OR try:
var no = 0;
$(document).on("click","[name=ADDINPUT]",function(){
++no;
var inp = "<input type='text' name='ADDTXT"+ no +"'>";
$("#SETSET").append(inp);
});