Editor in a dialog not working
Hi
I want to build a little note editor using the dialog widget. I have coded the following but whilst it works in IE8 it doesn't work in FireFox 3.5.8. In FF, saves don't show up and, once you edit the text in the dialog, all new dialogs show that edited text.
What am I doing wrong?
Chris
- <html>
- <head>
- <title>Note editing</title>
- <!--- include jQuery --->
- <link type="text/css" href="/jQuery/css/sunny/jquery-ui-1.7.2.custom.css" rel="stylesheet" />
<script type="text/javascript" src="/jQuery/jquery-1.4.1.js"></script>
- <script type="text/javascript" src="/jQuery/jquery-ui-1.7.2.js"></script>
- <script type="text/javascript">
- $(document).ready(function() {
- setNotes();
- });
- </script>
- </head>
- <body>
- <h1>Notes editing example</h1>
<script language="JavaScript">
- var currentlyEditingNoteID = 0; // keep track of which note is being edited
- var newNoteID = 100; // used to number new notes
- function setNotes() {
- // add initial notes as anchors inside divs in the notesPane div
- $("#notesPane").append("<div class='notes'><a href='javascript:;' onClick='editNote(1001)' id='history.note.n1001'>Test note number one</a></div>" )
- $("#notesPane").append("<div class='notes'><a href='javascript:;' onClick='editNote(1002)' id='history.note.n1002'>Test note number two</a></div>" )
- $("#notesPane").append("<div class='notes'><a href='javascript:;' onClick='editNote(1003)' id='history.note.n1003'>Another test note</a></div>" )
- }
- function addNote() {
- // get the next new note id
- var anID = newNoteID;
- // increment the id
- newNoteID++;
- // add a new note, concatenating the new id to the id of the anchor
- $("#notesPane").append("<div class='notes'><a href='javascript:;' onClick='editNote(" + anID + ")' id='history.note.n" + anID + "'>A new note</a></div>" )
- // open the new note for editing
- editNote(anID);
- }
- function editNote(anID) {
- // remeber which note we are on
- currentlyEditingNoteID = anID;
- // start with the current contents of the relevant note div in the noteEditor textarea
- var target = "#history\\.note\\.n" + currentlyEditingNoteID;
- $("#noteEditor").html($(target).html());
- // create the dialog afresh
- $("#pnlEditNotes").dialog({ height: 330, width: 400,
- modal: true, title: "Notes",
- close: function(event, ui) { killNoteDialog(); }
- });
- }
- function cancelNote() {
- // close and kill the dialog
- $("#pnlEditNotes").dialog("close");
- killNoteDialog();
- }
-
function saveNote() {
- // get the editted text out of the noteEditor textarea
- var newNoteText = $("#noteEditor").html();
- // put the new note text in the relevant anchor
- var target = "#history\\.note\\.n" + currentlyEditingNoteID;
- $(target).html(newNoteText);
- // close and kill the dialog
- $("#pnlEditNotes").dialog("close");
- killNoteDialog();
- }
-
function killNoteDialog() {
- // remove the dialog from the DOM
- $("#pnlEditNotes").dialog("destroy");
- }
- </script>
- <style>
- .notes {background-color: Honeydew; border: 1px solid silver; width: 100%}
- </style>
- <div id="pnlEditNotes" style="display:none" class="addDialog">
<!--- the hidden dialog definition --->
<table width="100%">
- <tr><td>Click on a note to edit it, or type a new note</td></tr>
- <tr><td><textarea id="noteEditor" style="width: 90%"></textarea></td></tr>
- <tr><td align="right">
- <input type="Button" value="Save" onclick="saveNote()">
- <input type="Button" value="Cancel" onclick="cancelNote()">
- </td></tr>
- </table>
- <!--- end of dialog definition --->
- </div>
- <div id="tNotes" class="tab" >
- <strong>Notes</strong> <input type="Button" value="+" class="buttonActive" title="Add new note..." onclick="addNote()"><br>
- <div id="notesPane"></div>
- </div>
- </body>
- </html>