jQuery: The Write Less, Do More JavaScript Library

repeating a block of <input text>s

View: New views
6 Messages — Rating Filter:   Alert me  

repeating a block of <input text>s

by ryo-6 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message


i have a page where i fill a form with personal data such as name,
surname, email...
i'm using the bassistance.de autocomplete plugin to retrieve data from
a db, typing the first letters of a name in the first input box and
then clicking on the desired row.

i do the same thing in another section of the same form, where i
search for items' details, such as item_code, color, price: i write
the first letters into the input box of the item_code, and the plugin
searches in the db...
and it works.

of course i'd like to add more than one article... and that's my
drama.

i put the code to obtain another "block" of <input text>s into a var,
and i have an [add another article] button that writes the new block
into the page when i click it.

the problem is that the autocomplete plugin works on div IDs.

well, if i assign a different ID to each autocompleting input, the
autocomplete plugin doesn't work (say, i have IDs such as foo0, foo1,
foo2 where the plugin looks for #foo);
if i use always the same ID (such as foo), the autocomplete works just
for the input field of the first block.

i can't imagine another way to obtain a similar result: having a bunch
of input texts i can repeat clicking on a button, where all the first
input boxes work with autocomplete.

please, could you help me?

thanks in advance
 ryo

Re: repeating a block of <input text>s

by Jörn Zaefferer-2 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message


The plugin doesn't rely on IDs. Please revisit your code without that
assumption and post a testpage if you don't get any further.

Jörn

On Fri, May 9, 2008 at 11:00 AM, ryo <rino.sassi@...> wrote:

>
> i have a page where i fill a form with personal data such as name,
> surname, email...
> i'm using the bassistance.de autocomplete plugin to retrieve data from
> a db, typing the first letters of a name in the first input box and
> then clicking on the desired row.
>
> i do the same thing in another section of the same form, where i
> search for items' details, such as item_code, color, price: i write
> the first letters into the input box of the item_code, and the plugin
> searches in the db...
> and it works.
>
> of course i'd like to add more than one article... and that's my
> drama.
>
> i put the code to obtain another "block" of <input text>s into a var,
> and i have an [add another article] button that writes the new block
> into the page when i click it.
>
> the problem is that the autocomplete plugin works on div IDs.
>
> well, if i assign a different ID to each autocompleting input, the
> autocomplete plugin doesn't work (say, i have IDs such as foo0, foo1,
> foo2 where the plugin looks for #foo);
> if i use always the same ID (such as foo), the autocomplete works just
> for the input field of the first block.
>
> i can't imagine another way to obtain a similar result: having a bunch
> of input texts i can repeat clicking on a button, where all the first
> input boxes work with autocomplete.
>
> please, could you help me?
>
> thanks in advance
>  ryo
>

Re: repeating a block of <input text>s

by ryo-6 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message


thanks alot for your answer, jorn.

you're right about the plugin not relying on IDs, anyway i can't
figure out how to solve my problem.
i tried generating the second block o input boxes this way:
---------------------------------------------------
  $("#add").click(function(){

  var codex = "<div class=\"item\" style=\"border: 1px solid #999;
width: 700px;\">ART # <input class=\"ainput\" type=\"text\" name=
\"art[]\" size=\"50\"><br><br>Description <input type=\"text\" name=
\"descr[]\" id=\"descr\" size=\"50\"><br><br>Color <input type=\"text
\" name=\"colore[]\" id=\"colore\" size=\"10\"></div>";

  $(".mark").append(codex);
  });
---------------------------------------------------
see: http://www.monokraft.com/test/test.html

but just the first 'ART #' works.

if you have any idea to help, you're welcome.

 rino

Re: repeating a block of <input text>s

by Jörn Zaefferer-2 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message


Please take a look at this:
http://docs.jquery.com/Frequently_Asked_Questions#Why_do_my_events_stop_working_after_an_Ajax_request.3F

Think of "creating elements on the clientside" when "loading elements
via ajax" or similar is mentioned.

Jörn

On Tue, May 13, 2008 at 2:14 PM, ryo <rino.sassi@...> wrote:

>
>  thanks alot for your answer, jorn.
>
>  you're right about the plugin not relying on IDs, anyway i can't
>  figure out how to solve my problem.
>  i tried generating the second block o input boxes this way:
>  ---------------------------------------------------
>   $("#add").click(function(){
>
>   var codex = "<div class=\"item\" style=\"border: 1px solid #999;
>  width: 700px;\">ART # <input class=\"ainput\" type=\"text\" name=
>  \"art[]\" size=\"50\"><br><br>Description <input type=\"text\" name=
>  \"descr[]\" id=\"descr\" size=\"50\"><br><br>Color <input type=\"text
>  \" name=\"colore[]\" id=\"colore\" size=\"10\"></div>";
>
>   $(".mark").append(codex);
>   });
>  ---------------------------------------------------
>  see: http://www.monokraft.com/test/test.html
>
>  but just the first 'ART #' works.
>
>  if you have any idea to help, you're welcome.
>
>   rino
>

Re: repeating a block of <input text>s

by ryo-6 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message


perfect, jorn. i used the LiveQuery plugin, and it works:
http://www.monokraft.com/test/test.html

the problem is that when i autocomplete the second article, the first
block takes the same values than the second one, i think it's beacause
the class names are the same.
i tried to add an incrementing index to the var names, but then i
don't know hot to reference them in the autocomplete script.

rino



Re: repeating a block of <input text>s

by ryo-6 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message


well, now it seems to be working simply by adding
:last
to the code updating the input text values, like that:
-------------------
if (ajaxdata)
   $(".ainput:last").val(ajaxdata[1]);
   $(".descr:last").val(ajaxdata[2]);
   $(".color:last").val(ajaxdata[3]);
-------------------

thanks for the... brainstorming.
i'gg now go ahead with my project.

rino