In the sample code above, I suspect that you've given the wrong id the
second input field...

With that oops mistake corrected, I strongly recommend that (if you've
not already done so), get Firefox and install the latest Firebug add-
in (and I also recommend the Web Developer toolbar).  I've found these
to be incredibly useful as I've wrestled with Prototype.  Firebug will
allow you to observer all of the AJAX HTTP requests in your code.
Chrome and IE also have some limited developer tools but IMHO, Firebug
is the most comprehensive and is easiest to use.

Using Firebug with your form and script above, I get the following
request in Firebug's console window:

   <i>http://localhost/test/product_process.php?product=%5Bobject
%20HTMLInputElement%5D&price=%5Bobject%20HTMLInputElement
%5D&wprice=null</i>

>From that it is obvious (ha ha ha) that your Javascript statement:
      var price = escape($('products_price'+id));
is returning the object rather than the value of the object - i.e. you
probably want
      var price = escape($('products_price'+id).value);
or (slightly shorter)
      var price = escape($F('products_price'+id));  //$F('id) is an
abbreviation for $('id').value

Of course, prototype gives you many ways to skin the cat...
You can add an id attribute to your forms - e.g.,
  <form name="product_update117" id="product_update117"
action="products.php" method="post">
  <form name="product_update118" id="product_update118"
action="products.php" method="post">
  <form name="product_update123" id="product_update123"
action="products.php" method="post">
   etc...
and then you can get all of the values in the form into a query string
via
  var pars = $( "product_update" + id ).serialize( );

However, to make this efficient on the receiving end, you probably
want to simplify the id's of the input fields so that they are the
same for all form (which will violate all sorts of rules relating to
id's supposedly being unique on the page)... its hard to tell how to
best handle this without knowing more about the code at the far end.

One last recommendation, bookmark the following link: 
http://www.prototypejs.org/api...
(I'd be lost without it ;-)

Hope this helps,

Al

On Jan 3, 7:50 pm, E <emiliano.jor...@templatecascade.com> wrote:
> Taking my first tentative steps in JavaScript and I have a stumbling
> block I can't get past.  I'm trying to submit an HTML form using the
> Ajax.Updater().  I have multiple versions of very similar forms on the
> same page and would like to seperate them by using a unique ID.
>
> My Javascript function is:
>
> function submitAJAX(id){
>         var url = 'product_process.php';
>         var price = escape($('products_price'+id));
>         var price_w = escape($('products_price_w'+id));
>         var pars = 'product=' + price + '&price=' + price + '&wprice=' +
> price_w;
>         var target = 'output-div' + id;
>         var myAjax = new Ajax.Updater(target, url, {method: 'get',
> parameters: pars});
>
> }
>
> The working part of my form looks something like this.
>
> <form name="product_update117" action="products.php" method="post">
> <input type="text" name="products_price117" value="25.0000"
> id="products_price117">
> <input type="text" name="products_price_w117" value="12.5000"
> id="products_price117">
>
> </form>
>
> I can't pull the values from product_update117 using what I am. But I
> need to somehow have multiple forms for multiple IDs created
> dynamically.  My whole approach might be wrong.  Or it just might be
> my inexperience with JavaScript. But after two days I can't figure it
> out.  I'm in the deep end.

--

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-scriptacul...@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