Page 1 of 1
Update a list through javascript
Posted: Thu Dec 29, 2011 10:13 pm
by hallsofvallhalla
I need a way of updating a HTML list through javascript.
I was thinking nesting the list inside of a form then changing the form.display.value but not having any luck.
Re: Update a list through javascript
Posted: Thu Dec 29, 2011 10:32 pm
by Chris
Updating it with information from the client or server?
Re: Update a list through javascript
Posted: Fri Dec 30, 2011 12:08 am
by hallsofvallhalla
client. No refresh. Dynamically
Re: Update a list through javascript
Posted: Fri Dec 30, 2011 1:54 am
by Chris
Code: Select all
<!DOCTYPE html>
<html>
<head>
<title>YW!</title>
<script type="text/javascript" src="http://code.jquery.com/jquery-1.7.1.min.js"></script>
<script type="text/javascript">
$(document).ready( function()
{
$('textarea[name="input"]').keyup( function()
{
// clear list
$('ol').html('');
// repopulate
var lines = $(this).val().split('\n');
for( var i in lines )
{
$('ol').append('<li>' + lines[i] + '</li>');
}
});
});
</script>
</head>
<body>
<ol>
<li>Line 1</li>
<li>Line 2</li>
</ol>
<textarea name="input">Line 1
Line 2</textarea>
</body>
</html>
Re: Update a list through javascript
Posted: Fri Dec 30, 2011 2:42 am
by hallsofvallhalla
THANKS you rock, i was able to pull out what I need.
Re: Update a list through javascript
Posted: Fri Dec 30, 2011 3:29 am
by Torniquet
jQuery saves the day again!
Need i say more? :p
Re: Update a list through javascript
Posted: Fri Dec 30, 2011 5:03 am
by hallsofvallhalla
haha yes I will give you that one

Re: Update a list through javascript
Posted: Fri Dec 30, 2011 6:05 pm
by hallsofvallhalla
once again, thanks Chris. This helped more than you know.