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

Recommended Answers

All 5 Replies

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.

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>

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

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

}
?>

using single textbox ,add two numbers through selector and function in PHP

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.