A minor mistake in the previous mail, please take this into consideration and neglect the previous mail :
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en"> <head> <script src="http://code.jquery.com/jquery-latest.pack.js" type="text/javascript" language="javascript" charset="utf-8"></script> <script type="text/javascript"> //<![CDATA[ $().ready(function(){ $('#clicy').click(function(){ var id = "word" + $('input[type!=hidden]').length; var hid = "hw" + $('input[type=hidden]').length; $('input[type=submit]').before('<br/><input type="hidden" name="'+hid+'" id="'+hid+'" value="&&"/><label for="'+id+'">&&</label><input type="text" name="'+id + '" id="'+id + '" value="" size="30" /><br/>'); return false; }); $('#clico').click(function(){ var id = "word" + $('input[type!=hidden]').length; var hid = "hw" + $('input[type=hidden]').length; $('input[type=submit]').before('<br/><input type="hidden" name="'+hid+'" id="'+hid+'" value="||"/><label for="'+id+'">||</label><input type="text" name="'+id + '" id="'+id + '" value="" size="30" /><br/>'); return false; }); }); //]]> </script> </head> <body> <form action="search/DoSearch" method="post"> <label for="word">Texto:</label> <input type="text" name="word" id="word" value="" size="50" /> <div><input type="submit" value="Buscar !!!" /></div> </form> <a href="" id="clicy">Adicionar criterio de búsqueda (&&)</a> | <a href="" id="clico">Adicionar criterio de búsqueda (||)</a> </body> </html> Thanks & Regards, Dhruva Sagar. Stephen Leacock<http://www.brainyquote.com/quotes/authors/s/stephen_leacock.html> - "I detest life-insurance agents: they always argue that I shall some day die, which is not so." On Wed, Nov 4, 2009 at 8:46 AM, Dhruva Sagar <dhruva.sa...@gmail.com> wrote: > Hi ReynierPM, > * > * > *The following is the test.html i've written for you, i've tweaked it a > bit to get the right id's & also to solve the 2 problems you listed.* > *Try it and see if it does what you wish to do :* > > <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en"> > <head> > <script src="http://code.jquery.com/jquery-latest.pack.js" > type="text/javascript" language="javascript" charset="utf-8"></script> > <script type="text/javascript"> > //<![CDATA[ > $().ready(function(){ > $('#clicy').click(function(){ > var id = "word" + $('input[type!=hidden]').length; > var hid = "hw" + $('input').length; > $('input[type=submit]').before('<br/><input type="hidden" name="'+hid+'" > id="'+hid+'" value="&&"/><label for="'+id+'">&&</label><input type="text" > name="'+id + '" id="'+id + '" value="" size="30" /><br/>'); > return false; > }); > $('#clico').click(function(){ > var id = "word" + $('input[type!=hidden]').length; > var hid = "hw" + $('input[type=hidden]').length; > $('input[type=submit]').before('<br/><input type="hidden" name="'+hid+'" > id="'+hid+'" value="||"/><label for="'+id+'">||</label><input type="text" > name="'+id + '" id="'+id + '" value="" size="30" /><br/>'); > return false; > }); > }); > //]]> > </script> > </head> > <body> > <form action="search/DoSearch" method="post"> > <label for="word">Texto:</label> > <input type="text" name="word" id="word" value="" size="50" /> > <div><input type="submit" value="Buscar !!!" /></div> > </form> > <a href="" id="clicy">Adicionar criterio de búsqueda (&&)</a> | <a > href="" id="clico">Adicionar criterio de búsqueda (||)</a> > </body> > </html> > > * > *Thanks & Regards, > Dhruva Sagar. > > > Ted Turner <http://www.brainyquote.com/quotes/authors/t/ted_turner.html> - > "Sports is like a war without the killing." > > On Wed, Nov 4, 2009 at 8:31 AM, ReynierPM <rper...@uci.cu> wrote: > >> Hi Dhruva: >> I'm trying to build a simple search form. Would be nice if the user can >> add her/his own fields for make the search better. What I mean? If you take >> only one input then the search will be limited to this only field containing >> one or more words. By the contrary if the user could add some fields and >> specify criteria like "&&" or "||" the search will be better. For that >> purpose I made some changes to the code. See below: >> >> <script type="text/javascript"> >> $().ready(function(){ >> $('#clicy').click(function(){ >> var id = "word" + $('input').length; >> var hid = "hw" + $('input').length; >> $('input:last').after('<br/><label for="'+id+'">&&</label><input >> type="text" name="'+id + '" id="'+id + '" value="" size="30" /> <input >> type="hidden" name="'+hid+'" id="'+hid+'" value="&&"/>'); >> return false; >> }); >> $('#clico').click(function(){ >> var id = "word" + $('input').length; >> var hid = "hw" + $('input').length; >> $('input:last').after('<br/><label for="'+id+'">||</label><input >> type="text" name="'+id + '" id="'+id + '" value="" size="30" /> <input >> type="hidden" name="'+hid+'" id="'+hid+'" value="||"/>'); >> return false; >> }); >> }); >> </script> >> >> <form action="search/DoSearch" method="post"> >> <label for="word">Texto:</label> >> <input type="text" name="word" id="word" value="" size="50" /> >> <div><input type="submit" value="Buscar !!!" /></div> >> </form> >> <a href="#" id="clicy">Adicionar criterio de búsqueda (&&)</a> | <a >> href="#" id="clico">Adicionar criterio de búsqueda (||)</a> >> >> As you notice here when I clic the link#clicy two fields are added: one >> hidden with && as value and another with word+id as id with no value. The >> same happen with the link#clico but the value of hidden field goes to ||. >> This code works fine but two things happen here. >> >> 1) When you click for first time in a link (#clicy or #clico) the field is >> added but I need add a hidden field just behind the input#word. How? >> >> 2) The fields are added just behind the SUBMIT button, how I can add just >> between the first field and the submit button? >> >> Cheers and thanks in advance >> >> -- >> Saludos >> ReynierPM >> > >