how to get value from 2 fields having same name in same time
Hi,
how to get value from 2 fields having same name in same time i mean to say when user select value form combo box he get the value not value form text field otherwise he will get value form text field but not 2 values simultaneously
i am using two fields in one column for time one is clock and second is combo so that user can change the time and when he clicks on save button the field should be saved in database
but the problem is when i am giving the same name to this filed user cant able to change time from combo box as it always display clock time
<tr>
<td width="29%" height="44">
<p align="right">Run at X Minutes:<br>
<b><font color="#008000">0</font> - <font color="#008000">59</font></b></td>
<td width="71%" height="44">
<select size="1" name="minutes">
<option selected value="-1">*</option>
<?fillDD(0, 59, -1);?>
</select> OR <input type="text" name="minutes" size="20"> <font size="1">(separate
multiple by comma)</font><br>
</td>
</tr>
<td bgcolor="#cccccc">
//time difference text field
<input size="1" class="button" type="text" value="0" name="ist" readonly>
</td>
<td>
<input type="button" class="button" value="Save" name="Save" border="1" onclick="calculateIst();">
</td>
<script language="JavaScript">
/* function show(){
var Digital=new Date()
var hours=Digital.getHours()
var minutes=Digital.getMinutes()
if (hours<=9)
hours="0"+ hours
if (minutes<=9)
minutes="0"+minutes
document.form.minutes.value=hours+":"+minutes
setTimeout("show()",1000)
}
show() */
function calculateIst()
{
var timeVon = new Date();
var timeMinutes = new Date();
var timeIst = new Date();
var time =document.forms["tstest"].elements["von"].value.split(":");
timeVon.setHours(time[0]);
timeVon.setMinutes(time[1]);
var time =document.forms["tstest"].elements["bis"].value.split(":");
timeBis.setHours(time[0]);
timeBis.setMinutes(time[1]);
timeIst.setTime(timeBis.getTime() - timeVon.getTime());
document.forms["tstest"].elements["ist"].value =timeIst.getHours()-1 + ":" + timeIst.getMinutes();
document.tstest.submit();
}
</script>
when i am selecting time from list its not displaying any selected time only text field is affected i dont no how to overcome this problem
hi,
sorry i dont understood actually i am using same name for field as minutes
and in the application i am using
[code]
$query = "SELECT minutes FROM t_emp order by nr DESC";
$result = mysql_query($query) or die("Query failed: Fetch all rows");
the problem is the text<input> field is clock and the combo is also same name so there is no chance of emptiness if you time could you please write me code how to get minutes from
$line["minutes"] when user did not select anything from combo as clock is there for <input> so it will take clock time and once combo feld is selcted then $line["minutes"] will show only selected combo not clock time----hope u understood this one---
Sorry i tried but didnt get the result i dont no why but i try to modify the code in this way
i dont understand why i am not getting time when user selects combo box,as i created field mytime in t_emp no clock field
so when user clicks on sumbit button he can view the result in theform itself,the idea behind this is suppose user forget to select time and clicks on submit the value of clock will submitted otherwise he can select from combo box then this value is displayed not the clock value,but using this code only combo value is coming not the clock value it always displaying combo value
Code:
<?PHP
if (isset($_POST["submit"])) {
if ($_POST["clock"] == "") {
$value = $_POST["mytime"];
}
else {
$value = $_POST["clock"];
}
echo $value;
}
if (isset($HTTP_POST_VARS["mytime"]))
{
$mytime = $HTTP_POST_VARS["mytime"];
$timediff = $HTTP_POST_VARS["timediff"];
$query = "INSERT INTO t_emp";
$query.="(mytime,timediff,datum) ";
$query.="('$mytime','$timediff')";
mysql_query($query) or die("Query failed: Insert new row");
}
$query = "SELECT mytime FROM t_emp order by nr DESC";
$result = mysql_query($query) or die("Query failed: Fetch all rows");
?>
<html>
<head>
</head>
<body>
<form name="myform" action="<?PHP echo $_SERVER["PHP_SELF"] ?>" method="post">
<select name="hr">
<option value="0">zero</option>
<option value="1">one</option>
<option value="2">two</option>
</select>
<select name="mytime">
<option value="0">zero</option>
<option value="1">one</option>
<option value="2">two</option>
</select><br>
<input type="text" name="clock"><br>
<input type="button" name="submit" value="Submit" onClick="calculatediff()">
while ($line = mysql_fetch_array($result, MYSQL_ASSOC)) {
<tr bgcolor="#FACB84">
<td><?= echo $value; ?></td>
<td><?= $line["timediff"] ?></td>
</tr>
<? } ?>
</form>
//get the clock always running as usual
<script language="JavaScript">
function show(){
var Digital=new Date()
var hours=Digital.getHours()
var minutes=Digital.getMinutes()
if (hours<=9)
hours="0"+ hours
if (minutes<=9)
minutes="0"+minutes
document.tstest.clock.value=hours+":"+minutes
setTimeout("show()",1000)
}
show()
function calculatediff()
{
var timeHr = new Date();
var timeMin= new Date();
var timeIst = new Date();
var time =document.forms["tstest"].elements["hr"].value.split(":");
timeHr.setHours(time[0]);
timeHr.setMinutes(time[1]);
var time =document.forms["tstest"].elements["mytime"].value.split(":");
timeMin.setHours(time[0]);
timeMin.setMinutes(time[1]);
timeIst.setTime(timeBis.getTime() - timeVon.getTime());
document.forms["tstest"].elements["timediff"].value =timeIst.getHours()-1 + ":" + timeIst.getMinutes();
document.tstest.submit();
}
</script>
<a href="formtest.php">formtest</a>
</body>
</html>
how to get selected time from application to show user what he selected time from combo or whether its clock i created one field as clock running and next to this field there is combo which he can select the time but unfortunately both r in one coulmn and when he selects he can see the selected time but when he forget to select something and clicks on save he wont get the clock time in GUI
$query = "INSERT INTO t_emp";
$query.="(mytime,timediff,datum) ";
$query.="('$mytime','$timediff')";
mysql_query($query) or die("Query failed: Insert new row");
}
$query = "SELECT mytime FROM t_emp order by nr DESC";
$result = mysql_query($query) or die("Query failed: Fetch all rows");
</tr>
<? } ?>
</form>
//get the clock always running as usual
<script language="JavaScript">
function show(){
var Digital=new Date()
var hours=Digital.getHours()
var minutes=Digital.getMinutes()
if (hours<=9)
hours="0"+ hours
if (minutes<=9)
minutes="0"+minutes
document.tstest.clock.value=hours+":"+minutes
setTimeout("show()",1000)
}
show()
function calculatediff()
{
var timeHr = new Date();
var timeMin= new Date();
var timeIst = new Date();
var time =document.forms["tstest"].elements["hr"].value.split(":");
timeHr.setHours(time[0]);
timeHr.setMinutes(time[1]);
var time =document.forms["tstest"].elements["mytime"].value.split(":");
timeMin.setHours(time[0]);
timeMin.setMinutes(time[1]);
timeIst.setTime(timeBis.getTime() - timeVon.getTime());
document.forms["tstest"].elements["timediff"].value =timeIst.getHours()-1 + ":" + timeIst.getMinutes();
document.tstest.submit();
}
I think you are going to want a conditional statement opposite of what I perviously posted, also, for this to work, set up your <select> something like this:
<?PHP
<td>
<? if ($_POST["mytime"] != "clock") {?>
<?= $line["mytime"] ?>// as this value comes from database
<? } ?>
<? else { ?>
//here i dont no how to get value as i sued javascript as
i want to show the user only clock time not 'mytime'
<?}?>
</td>
Bookmarks