www.webdeveloper.com
Results 1 to 11 of 11

Thread: how to get value from 2 fields having same name in same time

  1. #1
    Join Date
    Jun 2003
    Posts
    181

    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. #2
    Join Date
    Dec 2002
    Location
    High on life
    Posts
    10,104
    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. #3
    Join Date
    Jun 2003
    Posts
    181
    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. #4
    Join Date
    Dec 2002
    Location
    High on life
    Posts
    10,104
    As I said, I would give the fields two different names, and then do it something like this:

    PHP Code:
    <?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>

    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. #5
    Join Date
    Jun 2003
    Posts
    181

    Unhappy

    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>
    thanks in advance----
    arun krishnan

  6. #6
    Join Date
    Jun 2003
    Posts
    181

    no response

    no body is there to response about this problem
    arun krishnan

  7. #7
    Join Date
    Jun 2003
    Posts
    181

    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. #8
    Join Date
    Dec 2002
    Location
    High on life
    Posts
    10,104
    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. #9
    Join Date
    Dec 2002
    Location
    High on life
    Posts
    10,104
    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>
    and then you can check if they chose like this:

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

    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. #10
    Join Date
    Jun 2003
    Posts
    181
    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>
    <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 Code:
    <?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]
    arun krishnan

  11. #11
    Join Date
    Apr 2003
    Location
    Sweden
    Posts
    54
    Well... the problem is that:

    Code:
    $_POST["mytime"] != "clock"
    will never become false when your <select>-tag looks 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>
    Change the value of the first option to "clock" or change the condition of the test like this:

    Code:
    $_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!

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles