sunny sunny - 6 months ago 23
jQuery Question

How to remove Jquery PHP echo error?

I have a code of web form which have two fields Name with Date and Title. I use jquery in my code to display current date with calendar and when i change date in Date field it automatically change in Title field. I have some Hard code in Title field. Now my problem is that when i change date hard code is not display and my php code which is another file could not get value of title and could not store any value in data base mysql.

Here is my code.


<!doctype html>
<html lang="en">
<meta charset="utf-8">
<title>jQuery UI Datepicker - Default functionality</title>
<link rel="stylesheet" type="text/css" href="style.css">
<link rel="stylesheet" href="//">
<script src="//"></script>
<script src="//"></script>
<link rel="stylesheet" href="/resources/demos/style.css">
$(document).ready(function() {
dateFormat: "dd-M-y",
onSelect: function(dateText, inst) {
}).datepicker("setDate", new Date());

<form action="pd1.php" method="POST" enctype="multipart/form-data">

<table width="547" class="tblbdr" >
<td height="23" colspan="6" class="head"><p> Morning Breifing</p></td>
<tr> <td height="10"></td></tr>
<tr><td class="celltext"><b>Date:</b> </td> <td><input name="mydate" type="text" id="mydate" style="width:200px"> </td></tr>

<tr><td class="celltext"><b>Title: </b><br> </td>

<td class="celltext" style="width:200px" ><span id="dt_title"> <input name="title" type="text" value=" MB | Falcons |
<?php echo date("d-M-y");?>" style="width:200px"/> </span></b> </td> </tr>
<td class="celltext"><b>Upload File:</b></td>
<td colspan="4" bordercolorlight="#006666">
<input type="file" name="myfile" id="myfile" width="100%" size=80/>
<td><input type="submit" value="Save"/> </td> <td> </td>
<td width="151">

<td height="12">
<td width="290">

</td> </tr>

Here is my php code

Output without change in date


Output after change in date

output 2


By $("#dt_title").html(dateText); you delete input field inside your span, and only write plain date text. You should set value of your title input instead of spans html. Fixed code:

onSelect: function(dateText, inst) {
            $("#dt_title input[type='text']").val(dateText);

To keep title in input & only change date, you need to save title in additional attribute of input:

<input name="title" type="text" value=" MB | Falcons | <?php echo date("d-M-y");?>" data-title="MB | Falcons | " style="width:200px"/>

And then in jQuery change input value by adding title from attribute:

$("#dt_title input[type='text']").val($("#dt_title input[type='text']").attr('data-title')+dateText);