0

can u help me with this one?
can you gve me a sample code on how to add 2 values of textbox using php ?

5
Contributors
4
Replies
16
Views
6 Years
Discussion Span
Last Post by Bachu
0

Well, i think this is what you need.

<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post">

<input type="checkbox" name="q1[]" value="a" />value1<br>
<input type="checkbox" name="q1[]" value="b" />value2<br>
<input type="checkbox" name="q1[]" value="c" />value3<br>
<input type="submit" value = "submit" />
</form>

And then, you use something like :

$variable = $_POST['q1'];

or you define a variable that will go trought your values from q1 vector. Something like this:

for($i = 0; $i < count($_POST['q1']); $i++) //you are going trought the vector
$aux = $aux.$_POST['q1'][$i] //here, the variable $aux will get the options you have in your textbox.

I hope it helped you a bit, i am not a pro with php. Regards, Darius.

1

Hi

if you want in JS use the below code

<SCRIPT language = JavaScript>

function calculate() {
	document.getElementById("total").value =
    parseFloat(document.getElementById("one").value) +
    parseFloat(document.getElementById("two").value);
}

</SCRIPT>
<input name="one" type="text" value ="" size="5">

<input name="two" type="text" value ="" size="5" onChange="calculate()">
<P>
Total: <input name="total" type="text" value ="" size="5">
<P>
0

Hi,
I want to add up 2 dates and show the total days.
I have 2 textbox, Starting Date in 1st textbox and End Date in 2nd text box.
And I have to show toatl days in 3rd Textbox.
Like 2013-10-01 + 2013-10-03 = 2

Thanks & Regards,
Shamil Ahmed P

0

Hai;

Try this

<form name="dateForm" id="dateForm" method="post" action="#">
<label for="txtStartingDate">Starting Date</label>
<input type="text" name="txtStartingDate" id="txtStartingDate" value="<?php  echo (isset($_POST['txtStartingDate'])) ? $_POST['txtStartingDate'] : ""; ?>" />
<label for="txtEndDate">End Date</label>
<input type="text" name="txtEndDate" id="txtEndDate" value="<?php  echo (isset($_POST['txtEndDate'])) ? $_POST['txtEndDate'] : ""; ?>"  />
<input type="submit" name="sbtbtn" value="Submit" /> 
</form>

<?php
if(isset($_POST['sbtbtn'])){
$diff = abs(strtotime($_POST['txtStartingDate']) - strtotime($_POST['txtEndDate']));
$days = floor(($diff)/ (60*60*24));
?>
<label for="txtResult">Result</label>
<input type="text" name="txtResult" id="txtResult" value="<?php echo $days; ?>"  />
<?php

}
?>
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.