try this:
<!doctype html>
<html>
<head>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<script type="text/javascript">
$(document).ready(function () {
$('#subject').change(function (){
if($('#subject').val()=='newSub')
$('#newSubtxt').show();
else
$('#newSubtxt').hide();
});
$('#submitBTN').click(function(){
alert("post to data_handler.php");
var subject_id = $("#subject").val();
var newSubtxt = $("#newSubtxt").text();
$.ajax
({
url: 'data_handler.php',
data: {"subject_id": subject_id, "newSubtxt":newSubtxt},
type: 'post',
success: function(result)
{
alert("Data submitted!");
}
});
});
});
</script>
<meta charset="UTF-8">
<title>Untitled Document</title>
</head>
<form method="post" action="" name="cq">
<select name="subject" id="subject">
<option value="biology">Biology</option>
<option value="maths">Maths</option>
<option value="economics">Economics</option>
<option value="newSub"> Add New Subject </option>
</select>
<input type="text" name="newSubtxt" id="newSubtxt" style='display:none;'>
<button type="button" id="submitBTN">Send</button>
</form>
</body>
</html>
JSFiddle Here
data will be submitted to data_handler.php after Send clicked
UPDATE on OP request,
<?php
$style = "";
$theInputText = "";
if(isset($_POST['submit'])) {
$subject_val = $_POST['subject'];
if ($subject_val == "newSub"){
$newSubtxt_val = $_POST['newSubtxt'];
$theInputText = $newSubtxt_val;
} else {
$style = "display:none;";
}
}
?>
<!doctype html>
<html>
<head>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<script type="text/javascript">
$(document).ready(function () {
$('#subject').change(function (){
if($('#subject').val()=='newSub')
$('#newSubtxt').show();
else
$('#newSubtxt').hide();
});
});
</script>
<meta charset="UTF-8">
<title>Untitled Document</title>
</head>
<form method="post" action="<?php echo $_SERVER['PHP_SELF'];?>" name="cq">
<select name="subject" id="subject">
<option value="biology">Biology</option>
<option value="maths">Maths</option>
<option value="economics">Economics</option>
<option value="newSub"> Add New Subject </option>
</select>
<input type="text" name="newSubtxt" id="newSubtxt" style='<?php echo $style;?>' value="<?php echo $theInputText;?>">
<input type="submit" value="Send" name="submit" >
</form>
</body>
</html>
this will work according your comment, please add filter accordingly to prevent xss and sql injection.