Code:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://
www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>Script Example</title>
<script type="text/javascript">
var number = 1;
function add()
{
var table = document.getElementById('table');
var textfield = document.createElement('INPUT');
var a = document.createElement('A');
var li = document.createElement('LI');
textfield.setAttribute("Type", "text");
textfield.setAttribute("Name", "TextField_"+number);
textfield.setAttribute("Id", "TextField_"+number);
a.onclick = function()
{
remove (li);
remove(textfield);
remove(a);
}
a.innerHTML = "Remove";
table.appendChild(li);
li.appendChild(textfield);
li.appendChild(a);
number++;
}
function remove(removeItem)
{
removeItem.parentNode.removeChild(removeItem);
}
</script>
</head>
<body>
<a href="javascript:add()">Add</a>
<table id="table">
</table>
</body>
</html>
On Dec 26, 6:29 pm, Pierce <[email protected]> wrote:
> @Patrick Doyle
>
> I don't know about the first suggestion, but I know that the second
> option can work but brings up some problems... For example, when the
> page is refreshed the user looses all of the new fields. Also, it
> gets hard to manage in Javascript (at least the way that is below)
> because it gets a lot of code.
>
> @Michael Hendrickx
>
> Yeah, I kind of assumed it was hard to hard to understand. :) I have
> wrote a quick example using Javascript, which is below this text. I
> know how to do this in Javascript, but there are some problems so I am
> looking if there is a way to do this in Ruby on Rails. The problems
> with doing it in Javascript are outlined above.
>
> @Dejan Dimic
>
> As I said, I kind of guessed that it would be hard to understand. I
> hope the code below makes more sense, but if not just say so and I
> will try to explain it better. Pretty much, a button/link creates a
> new object and shows it on the page. Preferably it would not loose
> the new fields (and their values) on a refresh. I am doing a rewrite
> of a web application in Ruby on Rails, and am wondering how to avoid
> doing this in Javascript again.
>
> I suppose there really isn't a reason why I need to do this in Ruby on
> Rails, but Javascript brings up some problems and I think it may be
> easier in Ruby on Rails in general. If anyone could give me some
> advice about this, it would be great.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Ruby
on Rails: Talk" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---