Welcome!

Join our community of MMO enthusiasts and game developers! By registering, you'll gain access to discussions on the latest developments in MMO server files and collaborate with like-minded individuals. Join us today and unlock the potential of MMO server development!

Join Today!

Having each Field as a Value

MC Web Designs
Joined
Oct 28, 2010
Messages
888
Reaction score
111
Hi guys, basically, I need to be able to make a field have a certain value, then have the values counted up depending on the 'Number' that is inside the field.

For example, having a field set at '£5.00' and when I put '2' inside that field the total for that field will become '£10.00'.

I have I have been working on the variables and I've looked around to see if I could find my answer but the only thing I could find is using hidden HTML fields with JavaScript and that's not really what I want to do.

This is my Index.html so far:

PHP:
<form action="page2.php" method="post">
  <table width="419" border="0">
    <tr>
      <td>Ticket1</td>
      <td><input type="text" name="adult" /></td>
    </tr>
    <tr>
      <td>Ticket2</td>
      <td><input type="text" name="child" /></td>
    </tr>
    <tr>
      <td> </td>
      <td><input type="submit" value="Go!" /></td>
    </tr>
  </table>
</form>

AND this is my page2.php

PHP:
<?php
$adult = $_POST['adult'];
$child = $_POST['child'];
$sum = $adult + $child;	
?>
<table width="240" border="0">
  <tr>
    <td width="82">adult</td>
    <td width="148"><?php echo "£$adult.00"; ?></td>
  </tr>
  <tr>
    <td>child</td>
    <td><?php echo "£$child.00"; ?></td>
  </tr>
  <tr>
    <td>total:</td>
    <td><?php echo "£".$sum.".00"; ?></td>
  </tr>
</table>

I only need it quite simple and basic hence why I'm using tables etc. It's just something I'm experimenting with and then hopefully try and enhance it.

I am also aware that some of the methods I am using may not be the best way to go about doing things.

But yeah, if anyone could assist me with this that'd be awesome!

Many thanks,

Mathew Clarke
 
Initiate Mage
Joined
Oct 10, 2011
Messages
27
Reaction score
14
Could you not use a variable $qtyAdult and $qtyChild? Have a drop down combo box with each qty variables?

Example index
PHP:
<form action="page2.php" method="post"> 
  <table width="419" border="0"> 
    <tr> 
      <td>Ticket1</td> 
      <td><input type="text" name="adult" /></td>
	  <td>
		<select name="qtyAdult">
			<option value="1">1</option>
			<option value="2">2</option>
			<option value="3">3</option>
		</select>
	  </td>
    </tr> 
    <tr> 
      <td>Ticket2</td> 
      <td><input type="text" name="child" /></td>
	  <td>
		<select name="qtyChild">
			<option value="1">1</option>
			<option value="2">2</option>
			<option value="3">3</option>
		</select>
	  </td>
    </tr> 
    <tr> 
      <td> </td> 
      <td><input type="submit" value="Go!" /></td> 
    </tr> 
  </table> 
</form>

Page 2
PHP:
<?php 
$adult = $_POST['adult']; 
$child = $_POST['child'];
$qtyAdult = $_POST['qtyAdult'];
$qtyChild = $_POST['qtyChild'];

$totalAdult = $adult * $qtyAdult;
$totalChild = $child * $qtyChild;
$totalQty = $qtyAdult + $qtyChild;

$sum = $totalAdult + $totalChild;  
?> 
<table width="240" border="0"> 
  <tr> 
    <td width="82">adult</td> 
    <td width="148"><?php echo "£$adult.00 @ $qtyAdult"; ?></td> 
  </tr> 
  <tr> 
    <td>child</td> 
    <td><?php echo "£$child.00 @ $qtyChild"; ?></td> 
  </tr> 
  <tr> 
    <td>qty:</td> 
    <td><?php echo $totalQty; ?></td> 
  </tr> 
  <tr> 
    <td>total:</td> 
    <td><?php echo "£".$sum.".00"; ?></td> 
  </tr> 
</table>

Have fun!
 
Last edited:
MC Web Designs
Joined
Oct 28, 2010
Messages
888
Reaction score
111
Could you not use a variable $qtyAdult and $qtyChild? Have a drop down combo box with each qty variables?

Example index
PHP:
<form action="page2.php" method="post"> 
  <table width="419" border="0"> 
    <tr> 
      <td>Ticket1</td> 
      <td><input type="text" name="adult" /></td>
	  <td>
		<select name="qtyAdult">
			<option value="1">1</option>
			<option value="2">2</option>
			<option value="3">3</option>
		</select>
	  </td>
    </tr> 
    <tr> 
      <td>Ticket2</td> 
      <td><input type="text" name="child" /></td>
	  <td>
		<select name="qtyChild">
			<option value="1">1</option>
			<option value="2">2</option>
			<option value="3">3</option>
		</select>
	  </td>
    </tr> 
    <tr> 
      <td> </td> 
      <td><input type="submit" value="Go!" /></td> 
    </tr> 
  </table> 
</form>

Page 2
PHP:
<?php 
$adult = $_POST['adult']; 
$child = $_POST['child'];
$qtyAdult = $_POST['qtyAdult'];
$qtyChild = $_POST['qtyChild'];

$totalAdult = $adult * $qtyAdult;
$totalChild = $child * $qtyChild;
$totalQty = $qtyAdult + $qtyChild;

$sum = $totalAdult + $totalChild;  
?> 
<table width="240" border="0"> 
  <tr> 
    <td width="82">adult</td> 
    <td width="148"><?php echo "£$adult.00 @ $qtyAdult"; ?></td> 
  </tr> 
  <tr> 
    <td>child</td> 
    <td><?php echo "£$child.00 @ $qtyChild"; ?></td> 
  </tr> 
  <tr> 
    <td>qty:</td> 
    <td><?php echo $totalQty; ?></td> 
  </tr> 
  <tr> 
    <td>total:</td> 
    <td><?php echo "£".$sum.".00"; ?></td> 
  </tr> 
</table>

Have fun!
Cheers mate! That's awesome. I appreciate the assitance

Althought, it's not quite what I'm looking for.

What I was searching for is, because it's a ticket system; when you enter for say '1' into the textfield on the web page I want it to output '£15.00' because that's the price of the ticket. Then say replaced the '1' with '2', I want the form to output the cost of the tickets to '£30.00'.

So basically each field has it's own price to it and depending on the actual number entered inside the form, it will multiply it etc.
 
Last edited:
Infraction Baɴɴed
Member
Joined
Apr 9, 2008
Messages
1,416
Reaction score
169
have you looked into js?

idk much about js but i think in jquery theres a event for key unpress (*i think dont know for sure really tired sorry ): ) then the moment the event is triggered update the field you want
 
Praise the Sun!
Member
Joined
Dec 4, 2007
Messages
2,502
Reaction score
986
Cheers mate! That's awesome. I appreciate the assitance

Althought, it's not quite what I'm looking for.

What I was searching for is, because it's a ticket system; when you enter for say '1' into the textfield on the web page I want it to output '£15.00' because that's the price of the ticket. Then say replaced the '1' with '2', I want the form to output the cost of the tickets to '£30.00'.

So basically each field has it's own price to it and depending on the actual number entered inside the form, it will multiply it etc.

Real-time? If so, the only way to do that is through jQuery / javascript.

If not, I don't see how Soulah's example is wrong other than that he's using dropdown menu's rather than input fields.
 
Initiate Mage
Joined
Oct 10, 2011
Messages
27
Reaction score
14
If you can't figure out Javascript; then, why can't you just hardcode the amount and times it by the qty variables I provided?

PHP:
<?php
$adult = 15.00; 
$child = 7.00;
?>

You now can remove the $_POST['adult'] & $_POST['child'] textboxes.
You do not need javascript to do this.

EDIT: I also meant to have in my last post:
PHP:
<?php echo "$qtyAdult @ £$adult.00"; ?>
 
Last edited:
Hi, I'm Omar!
Member
Joined
Jan 6, 2011
Messages
1,345
Reaction score
646
Is this what you want?
Code:
<script type="text/javascript">
	$(document).ready(function(){
		$('#adult').change(function(){
			$('#adult').html($('#adult').val() * 2); // do the maths you want here
		});
	});
</script>

Edit; for that to work add id="adult" to your adult input.
 
MC Web Designs
Joined
Oct 28, 2010
Messages
888
Reaction score
111
Thanks for all the reply guys, I have not yet found what I am looking for though.

Basically I want the tickets booking to look like this:

Go to step 3 and use the + / - signs, you can also type in how many you want.

Now, when the tickets are selected you can see the prices being added up depending on how many tickets are ordered. So if I order two adult tickets, the cost comes to: £37.00.

That's what I am asking for, for the page to realize that the tickets have an individual cost.
 
Initiate Mage
Joined
Oct 10, 2011
Messages
27
Reaction score
14
I hope you find your answers soon!

Heres something that is very similar
 
Hi, I'm Omar!
Member
Joined
Jan 6, 2011
Messages
1,345
Reaction score
646


Kinda messy but ugh, League's patching so I had to waste some time.

Credits to Wizkidje for helping me out with something.
 
MC Web Designs
Joined
Oct 28, 2010
Messages
888
Reaction score
111
I hope you find your answers soon!

Heres something that is very similar

That is exactly what I was looking for! Thank you so much, I'll optimize this to make it work around what I need it to do!

Thank you to everyone else that tried to help!
 
Back
Top