www.webdeveloper.com
Recent Articles
  • Finding Slow Running Queries in ASE 15
  • A More Advanced Pie Chart for Analysis Services Data
  • Adobe AIR Programming Unleashed: Working with Windows
  • Performance Testing SQL Server 2008's Change Data Capture Functionality
  • The ABC's of PHP: Introduction to PHP
  • How to Migrate from BasicFiles to SecureFiles Storage
  • Why the Twitter Haters Are Wrong
  • User Personalization with PHP: Beginning the Application
  • Whats in an Oracle Schema?
  • Lighting Enhancement in Photoshop
  •  

    Go Back   WebDeveloper.com > Server-Side Development > PHP

    PHP Discussion and technical support for using and deploying PHP based websites.

    Reply
     
    Thread Tools Search this Thread Rate Thread Display Modes
      #1  
    Old 06-16-2003, 07:39 AM
    zuzupus zuzupus is offline
    Registered User
     
    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
    Reply With Quote
      #2  
    Old 06-16-2003, 07:54 AM
    pyro's Avatar
    pyro pyro is offline
    Registered User
     
    Join Date: Dec 2002
    Location: High on life
    Posts: 10,183
    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!
    Reply With Quote
      #3  
    Old 06-16-2003, 08:32 AM
    zuzupus zuzupus is offline
    Registered User
     
    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
    Reply With Quote
      #4  
    Old 06-16-2003, 08:51 AM
    pyro's Avatar
    pyro pyro is offline
    Registered User
     
    Join Date: Dec 2002
    Location: High on life
    Posts: 10,183
    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!
    Reply With Quote
      #5  
    Old 06-16-2003, 09:38 AM
    zuzupus zuzupus is offline
    Registered User
     
    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
    Reply With Quote
      #6  
    Old 06-17-2003, 03:37 AM
    zuzupus zuzupus is offline
    Registered User
     
    Join Date: Jun 2003
    Posts: 181
    no response

    no body is there to response about this problem
    __________________
    arun krishnan
    Reply With Quote
      #7  
    Old 06-17-2003, 08:38 AM
    zuzupus zuzupus is offline
    Registered User
     
    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
    Reply With Quote
      #8  
    Old 06-17-2003, 08:52 AM
    pyro's Avatar
    pyro pyro is offline
    Registered User
     
    Join Date: Dec 2002
    Location: High on life
    Posts: 10,183
    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!
    Reply With Quote
      #9  
    Old 06-17-2003, 08:56 AM
    pyro's Avatar
    pyro pyro is offline
    Registered User
     
    Join Date: Dec 2002
    Location: High on life
    Posts: 10,183
    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!
    Reply With Quote
      #10  
    Old 06-17-2003, 09:38 AM
    zuzupus zuzupus is offline
    Registered User
     
    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
    Reply With Quote
      #11  
    Old 06-17-2003, 07:02 PM
    mf22cs mf22cs is offline
    Member
     
    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!
    Reply With Quote
    Reply

    Bookmarks


    Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
     
    Thread Tools Search this Thread
    Search this Thread:

    Advanced Search
    Display Modes Rate This Thread
    Rate This Thread:

    Posting Rules
    You may not post new threads
    You may not post replies
    You may not post attachments
    You may not edit your posts

    BB code is On
    Smilies are On
    [IMG] code is Off
    HTML code is Off
    Forum Jump


    All times are GMT -5. The time now is 03:37 AM.



    Acceptable Use Policy

    internet.comMediabistrojusttechjobs.comGraphics.com

    WebMediaBrands Corporate Info


    Advertise | Newsletters | Feedback | Submit News

    Legal Notices | Licensing | Permissions | Privacy Policy

    Powered by vBulletin® Version 3.7.3
    Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.