Click to See Complete Forum and Search --> : how to get value from 2 fields having same name in same time


zuzupus
06-16-2003, 06:39 AM
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

hope this time no problem in understanding

[code]

<?
function fillDD($min, $max, $selected) {
for($i=$min; $i<$max+1; $i++) {
if($i == $selected) {
print("<option SELECTED value=\"$i\">$i</option>\n");
} else {
print("<option value=\"$i\">$i</option>\n");
}
}
}
?>

<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

thanks

pyro
06-16-2003, 06:54 AM
You will have to give them different names. Give you <select> one name, and you <input> antother. Then, check if the <input> is blank like this:

if ($_POST["inputname"] == "") { #can use $_GET

If it is, you can check your <select> if not, you just use the <input>...

zuzupus
06-16-2003, 07:32 AM
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");

<? while ($line = mysql_fetch_array($result, MYSQL_ASSOC)) { ?>
<td><?= $line["minutes"] ?></td>

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---

thanks

pyro
06-16-2003, 07:51 AM
As I said, I would give the fields two different names, and then do it something like this:

<?PHP
if (isset($_POST["submit"])) {
if ($_POST["mytext"] == "") {
$value = $_POST["myselect"];
}
else {
$value = $_POST["mytext"];
}
echo $value;
}
?>
<html>
<head>
</head>
<body>
<form name="myform" action="<?PHP echo $_SERVER["PHP_SELF"] ?>" method="post">
<select name="myselect">
<option value="0">zero</option>
<option value="1">one</option>
<option value="2">two</option>
</select><br>
<input type="text" name="mytext"><br>
<input type="submit" name="submit" value="Submit">
</form>
<a href="formtest.php">formtest</a>
</body>
</html>

zuzupus
06-16-2003, 08:38 AM
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


<?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>


thanks in advance----

zuzupus
06-17-2003, 02:37 AM
no body is there to response about this problem

zuzupus
06-17-2003, 07:38 AM
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



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>
--------------------------------------------------------------------------------

pyro
06-17-2003, 07:52 AM
Note: Please do not start new threads on the same topic. The threads have been merged.

pyro
06-17-2003, 07:56 AM
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:

<select name="mytime">
<option value="choose">Please Choose</option>
<option value="0">zero</option>
<option value="1">one</option>
<option value="2">two</option>
</select>

and then you can check if they chose like this:

<?PHP
if ($_POST["mytime"] != "choose") {
#They chose the time
}
else {
#They did not choose a time -- use your default
}

zuzupus
06-17-2003, 08:38 AM
sorry still got problem.....

<select name="mytime">
<option value="choose">Please Choose</option>
<option value="0">zero</option>
<option value="1">one</option>
<option value="2">two</option>
</select>
<input type="text" class="button" size="1" name="clock">

the vaule of clock i m getting using javascript u can see from thsi site http://www.javascriptkit.com/script/cut2.shtml

now probelm is when

and then you can check if they chose 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>
[/B][/QUOTE]

mf22cs
06-17-2003, 06:02 PM
Well... the problem is that:


$_POST["mytime"] != "clock"


will never become false when your <select>-tag looks like this:


<select name="mytime">
<option value="choose">Please Choose</option>
<option value="0">zero</option>
<option value="1">one</option>
<option value="2">two</option>
</select>


Change the value of the first option to "clock" or change the condition of the test like this:


$_POST["mytime"] != "choose"


/Marcus

PS!
I took a look at some of the previus codeblocks, and it seems to be the same error... but diffrent values.'
DS!