Hello Larry,

First of all how did you find this mailing list? You haven't used a single
Prototype method in your code?

You might want to have a look at the following sections:

Creating elements (and adding attributes at the same time):
http://api.prototypejs.org/dom/Element/new/

Or adding attributes using:
http://api.prototypejs.org/dom/Element/writeAttribute/

And also inserting elements into existing elements:
http://api.prototypejs.org/dom/Element/insert/

Further more on how to handle events such as clicks:
http://api.prototypejs.org/dom/Event/on/

And now to your actual problem, you click a button multiple times and each
time you click the button your handler creates a new button. Without even
thinking about JavaScript, how should any programming language solve this?
You don't want multiple elements, so check if the element you are about to
create exists?

This could be done by checking if an element with the exact same ID you're
about to create already exists. This can be done using the dollar function,
which accepts elements or element id's (
http://api.prototypejs.org/dom/dollar/).

if (!$('elementId')) {
 // The element does not exist yet, create and insert the new element.
}

I hope you can use the information I gave you, please check the API on how
to handle specific tasks with the Prototype Library first.

Greetings,
 Johan

On Fri, Jun 29, 2012 at 1:11 AM, Larry <lholdswo...@gmail.com> wrote:

> Hi, I'm very new to Prototype Javascript so any help would be greatly
> appreciated.
>
> My issue is this, I have a form that does calculations. At the bottom
> of the form there is a button that when clicked updates the totals and
> displays it at the bottom of the page. Here is the code for the
> button.
>
>  <input type="button" name="update" id="update" value="Update Total"
> onclick="footprintcalc.total(); footprintcalc.addElement();" />
>
> This button actually does 2 things totals the numbers in the form like
> I mentioned above but also adds a hidden input box that also holds the
> totals. Here is the piece of code that does that.
>
> addElement: function () {
>        var theNewElem = document.createElement('input');
>        theNewElem.setAttribute('type', '');
>        theNewElem.setAttribute('id', 'finaltons');
>        theNewElem.setAttribute('value', totaltotal);
>        document.getElementById('formtons').appendChild(theNewElem);
>    }
>
> };
>
> This hidden input box with the id finaltons,  is used to set a session
> variable which can be used to transfer my final total to another page.
> This part is done in C#.
>
> My problem is, if you hit the "Update Total" button multiple times I
> get multiple hidden input box's which causes a problem with my session
> variable. So what do I have to add to my code so it doesn't add the
> input box if its already exists. Can this be done?
>
> --
> You received this message because you are subscribed to the Google Groups
> "Prototype & script.aculo.us" group.
> To post to this group, send email to
> prototype-scriptaculous@googlegroups.com.
> To unsubscribe from this group, send email to
> prototype-scriptaculous+unsubscr...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/prototype-scriptaculous?hl=en.
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"Prototype & script.aculo.us" group.
To post to this group, send email to prototype-scriptaculous@googlegroups.com.
To unsubscribe from this group, send email to 
prototype-scriptaculous+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/prototype-scriptaculous?hl=en.

Reply via email to