/    Sign up×
Community /Pin to ProfileBookmark

Update hide field only when "close" drop down selected

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:

[code=php]
<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 :&nbsp; <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>
[/code]

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:

[code=php]
<?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′”);
?>
[/code]

I dont know where i am missing it.
Just need some correction in my code.
Thanks in advance.

to post a comment
PHP

0Be the first to comment 😎

×

Success!

Help @jackgoddy123 spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.18,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...