I have a webpage with a textbox named “title” and a text editor window that represents content.
I have this javascript variable:
var article = {"title" : "I am a title", "content" : "I am the content"};
I must admit and I’ve never ran into this kind of array before in javascript, that’s why I need help.
Here’s my code of the HTML page:
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
...
<script type="text/javascript">
var article = {"title" : "I am a title", "content" : "I am the content"};
</script>
</head>
<body>
<form name="myForm" method="post">
<label>Title:</label><br />
<input id="myTitle"></input><br /><br />
<label>Content:</label><br />
<textarea id="myContent" name="myContent" rows="15" cols="80" style="width: 80%">
</textarea><br /><br />
<input type="submit" value="save" />
</form>
</body>
</html>
What I need to add to the webpage functionality is this:
- When page loads, put in the title textbox and inside the textarea (where the text editor is) the values in the article variable (in this case “I am a title” in the title, and “I am the content” in the editor).
- Once I change the values inside those textbox and textarea, the variable itself should be updated to what I’ve written.
Unfortunately for me, I have never ran into this kind of variable, so I’d be glad for some guidance.
Try this:
DEMO HERE