|
|||||||
| PHP Discussion and technical support for using and deploying PHP based websites. |
![]() |
|
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
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 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
__________________
arun krishnan |
|
#2
|
||||
|
||||
|
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>...
__________________
Personal website http://www.ryanbrill.com/ Business website: http://www.infinitywebdesign.com/ TypeSpace http://www.typespace.org/ I reject your reality and substitute it with my own! |
|
#3
|
|||
|
|||
|
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
__________________
arun krishnan |
|
#4
|
||||
|
||||
|
As I said, I would give the fields two different names, and then do it something like this:
PHP Code:
__________________
Personal website http://www.ryanbrill.com/ Business website: http://www.infinitywebdesign.com/ TypeSpace http://www.typespace.org/ I reject your reality and substitute it with my own! |
|
#5
|
|||
|
|||
|
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>
__________________
arun krishnan |
|
#6
|
|||
|
|||
|
no response
no body is there to response about this problem
__________________
arun krishnan |
|
#7
|
|||
|
|||
|
visibilty
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> --------------------------------------------------------------------------------
__________________
arun krishnan |
|
#8
|
||||
|
||||
|
Note: Please do not start new threads on the same topic. The threads have been merged.
__________________
Personal website http://www.ryanbrill.com/ Business website: http://www.infinitywebdesign.com/ TypeSpace http://www.typespace.org/ I reject your reality and substitute it with my own! |
|
#9
|
||||
|
||||
|
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:
Code:
<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> PHP Code:
__________________
Personal website http://www.ryanbrill.com/ Business website: http://www.infinitywebdesign.com/ TypeSpace http://www.typespace.org/ I reject your reality and substitute it with my own! |
|
#10
|
|||
|
|||
|
sorry still got problem.....
Code:
<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> 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 Code:
__________________
arun krishnan |
|
#11
|
|||
|
|||
|
Well... the problem is that:
Code:
$_POST["mytime"] != "clock" Code:
<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> Code:
$_POST["mytime"] != "choose" PS! I took a look at some of the previus codeblocks, and it seems to be the same error... but diffrent values.' DS! |
![]() |
| Bookmarks |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|