0

i have created a form for payment and retrieved data from database to the input fields. my html is below:

<table>
	<form name="postForm" action="form_process.php" method="POST" >
	<tr><td><input type="hidden" name="txnid" value="<?php echo $txnid=time().rand(1000,99999); ?>" /></td></tr>
	<tr><td>amount</td><td><input type="text" name="amount" value="<?php echo $_GET['id'];?>" /></td></tr>



	<tr><td>Name</td><td><input type="text" name="firstname" value="<?php echo $user_name; ?>" /></td></tr>
	<tr><td>email</td><td><input type="text" name="email" value="<?php echo $_SESSION['email']; ?>" /></td></tr>
	<tr><td>phone</td><td><input type="text" name="mobile" value="<?php echo $user_mobile; ?>" /></td></tr>
	<tr><td>productinfo</td><td><input type="text" name="productinfo" value="" /></td></tr>
	<tr><td><input type="hidden" name="surl" value="success.php" size="64" /></td></tr>
	<tr><td><input type="hidden" name="furl" value="fail.php" size="64" /></td></tr>
	<tr><td><input type="submit" /></td><td><input type="reset" /></td></tr>
	</form>
</table>

i have the following design for my website for customers to choose plans. when the user clicks the paynow button, they are redirected to this form. enter image description here

when the use clicks the button,the corresponding amount should be added to the input field automatically. if its 400 the input should be 400 or 300 if 300. how can i do this inside submit button?

11
  • which input field needs the value ? Commented Jun 4, 2018 at 9:45
  • Try this Commented Jun 4, 2018 at 9:48
  • @melvin amount field Commented Jun 4, 2018 at 9:48
  • where is the amount field in code ? Commented Jun 4, 2018 at 9:49
  • 3rd line. at the top Commented Jun 4, 2018 at 9:50

3 Answers 3

0

So you need to perform an click function on button. Your 3 buttons may have a data attribute price mentioning the value like

<input type="button" data-price="300">

By acessing the data attribute you fill the input field.

$('.button').click(function(){
    $('input[name="amount"]').val($(this).data(price));
});
Sign up to request clarification or add additional context in comments.

8 Comments

where should i add this
In your js file.
let me check and tell
I don't see jQuery in his tag list?!
so ? He don't know to do it So he asked for help. Also there is a tag javascript .I don't know whether it is possible without js @RezaSaadati
|
0

Instead of Submit You can give input type as Button like plan1,plan2,plan3 and create onClick function for each button for example

<button onclick="plan1()">Plan1</button>

<p id="plan1">Plan1 contents</p>

<script>
function plan1() {
  document.getElementById("plan1").innerHTML = "Document Data";
}

like wise

Comments

0
  1. Add the following class to your 3 sections: class="month"

  2. Give that input field an ID where you want the result to be outputed: e.g: <input type="text" name="productinfo" id="productinfo">

  3. Add following script in your JavaScript file: const month = document.querySelectorAll('.month'); const productInfo = document.getElementById('productinfo'); month.forEach((m) => m.addEventListener('click', (e) => productInfo.value = m.getAttribute('data-month')));

data-month contrains the value. In this case 100, 200, 300.

const month = document.querySelectorAll('.month');
const productInfo = document.getElementById('productinfo');

month.forEach((m) => m.addEventListener('click', (e) => productInfo.value = m.getAttribute('data-month')));
<input class="month" type="button" value="PLAY NOW" data-month="100">
<input class="month" type="button" value="PLAY NOW" data-month="200">
<input class="month" type="button" value="PLAY NOW" data-month="300">

<input type="text" id="productinfo">

5 Comments

where should i give the id=month
@kingkhan sorry, my bad. It's not an ID. It should be a class. So add to all your buttons: class="month".
i have done as you said but the value is not aded to the box
@kingkhan did you add the ID productinfo to the input text field, which should receive the value?
@kingkhan where is your JavaScript loaded? In <head> or in footer? If not in footer, please place it in the footer. Also please tell me the error of your console.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.