I wrote the following JavaScript code for saving a document:
function save()
{
$.prompt('Are you sure you want to save changes to this document?',{
callback: savechanges,
buttons: { Yes: 'Yes', No: 'No' }
});
function savechanges(v,m){
document.write('Date hello: ', page);
if(v=="Yes")
{
var content = $('#content').val();// This line is not running
var page = trim($('#pageid').val()); // This line is not running
content = escape(content);
$.post("../gamescripts/save.php",
{ page: page, content: content },
function(data){
if(trim(data)=="success")
{
document.location = page ;
}
});
}
}
}
But the following two jQuery lines are unable to extract the data from content and page id: But, they are not generating any errors
var content = $('#content').val();
var page = trim($('#pageid').val());
This is the php file which calls the JavaScript function. I have included the jquery.js library. Do I need to include any other library?
<script type="text/javascript" src="../gamejavascripts/jquery.js"></script>
<form id="form1" name="form1" method="post" action="javascript:save();">
<input name="pageid" type="text" id="pageid" value="<?php echo "$url"?>" READONLY/>
<textarea name="content" id= "content" cols="80" rows="18">";
<?php
$handle = fopen("$url","r");
while(!feof($handle))
{
$text = fgets($handle);
echo $text;
}
fclose($handle);
?>
</textarea>
<input type="submit" value="Save" />
</form>
This is the save.php file
<?php
$content= $_POST["content"];
$page= trim($_POST["pageid"]);
$text = rawurldecode($content);
$myFile = $page;
$fh = fopen($myFile, 'w') or die("can't open file");
$status= "success";
fwrite($fh, $text);
fclose($fh);
echo $status;
?>
If your are looking for
jQuerytrim function then use$.trim().You should not get any error in the below line though