Jump to content

Update hide field only when "close" drop down selected


jackgoddy123

Recommended Posts

Hello to all,

  I am updating a dropdown option field. But when i choose "Close" option then a textbox field with the current date appears.

Below is the code for it:

<html>
<head>

<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.10.1/jquery.min.js"></script>

<script>
$(document).ready(function () {
            $('#status').change(function () {
                if (this.value == "Close") {
                    $('#Other').show();
                } else {
                    $('#Other').hide();
                }

            });
        });


</script>
</head>
<body>
<form action="status2.php" method="post">
Status
<select id="status" name="status" value="<?=$row['status']?>">
                        <option>Choose</option>
                        <option value="Open">Open</option>
                        <option value="Inprocess">Inprocess</option>
                        <option value="Close">Close</option>
                    </select>
  <table>
             <tr id="Other" style="display: none">
                <td>
                   <!-- <input id="txtOthers" type="text" /> -->
				   <label>Lead Close Date :  <input type="text"  name="lead_close" value="<?php $b = time ();
  print date("d-m-y",$b) ; 
 ?> "  ><br />
  </td>
            </tr>
        </table>

<br/>
<input type="submit" value="Update" name="submit">
</form>
</body>
</html>

The above code works perfectly fine.

But when i update the records then even the hide textbox(lead_close)  gets update. It must only update when the close option gets selected orelse only status with "Open" or "Inprocess" must update.

Below is my update code:

<?php
$konek = mysql_connect("localhost","root","") or die("Cannot connect to server");
mysql_select_db("test",$konek) or die("Cannot connect to the database");

$status= ($_POST['status'])?$_POST['status']:'';

$lead_close= ($_POST['lead_close'])?$_POST['lead_close']:'';

mysql_query("update public set status='".$status."', lead_close='".$lead_close."' where id='1'");
?>

I dont know where i am missing it.

Just need some correction in my code.

Thanks in advance.

 

Link to comment
Share on other sites

Just change the logic to your processing code. If the status does not equal close, then don't update the close date. Also, the code for setting the status has a flaw since it would allow any value - not just the value you have on the form. You need to validate ALL date being sent from a user.

 

$konek = mysql_connect("localhost","root","") or die("Cannot connect to server");
mysql_select_db("test",$konek) or die("Cannot connect to the database");

$status = ($_POST['status']) ? $_POST['status'] : '';
$lead_close = ($status=='Close' && $_POST['lead_close']) ? $_POST['lead_close'] : '';

$query = "UPDATE public SET status='{$status}', lead_close='{$lead_close}' WHERE id='1'";
mysql_query($query);
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.