Anyone?

-------- Original Message --------
Subject: [jQuery] How to Add HTML to a page, and make it "active"?
Date: Thu, 09 Nov 2006 16:24:54 -0500
From: Scott Sharkey <[EMAIL PROTECTED]>
Reply-To: jQuery Discussion. <[email protected]>
Organization: Linux Unlimited, LLC
To: [email protected]

Hi All,

Relatively new to jQuery, and loving it so far.  Hopefully you can help
me with this one...

I have a "quote page", which has "line items" that fetch various pieces
of info (via ajax) from the server as the user starts "drilling down".
There are a variable number of "line items", of 4 different types.  I
have the code to create a new line item of a given type whenever the
user selects that type from a selection box.

Let's say one of the "line items" looks like this:

      Type: <select box: ceramic or metal>
      Material: <filled by ajax, depending on selection above>
      Description: <filled by ajax, depending on material selected>
      Quantity: <standard input field>

I've got the code to insert the HTML necessary for the above working so
far.  Only big problem here was generating a "unique id field" for the
fields, which I did by having a JavaScript global "item count", which is
incremented every time a new line item is added, and which is appended
to each field ID, ie type_1, material_1, desc_1, qty_1, etc.  When they
create a second line item (of any type) it's fields are appended with
_2, etc.

OK, now I have to "activate" the type_1 field, so that on a change,
it will fire off an ajax request to fetch the desired list of materials
for that "type" and fill in the (currently empty) material <div>.

Is this possible?

I *think* that I can do something like:

    $("#type_1").change(function() {
       var type = $("#type_1").val();
       $.post("/ajax/get_material_list.php", {type:type}, function(xml) {

          ... function body to process the xml results here...
          )};
       )};

except, of course that "#type_1" above needs to be a Javascript variable
string, rather than a constant.  Of course, the function body for
fetching the results must also "enable" an ajax call on a change to the
(new) material selection field, to fetch the description.

Am I even close to on the right track, or is there a better way to do
this?  Should I be generating the html on the server, with the
Javascript, and passing it back, instead of generating the html with
jQuery in the client?  ANY suggestions would be welcomed!

-Scott

_______________________________________________
jQuery mailing list
[email protected]
http://jquery.com/discuss/

_______________________________________________
jQuery mailing list
[email protected]
http://jquery.com/discuss/

Reply via email to