new member but I've been reading and learning here for a bit. I hope I"ve formatted this question correctly but here goes. Here's the basics of my problem. I'm using JQuery replaceWith to swap a dropdown select with an input box and vice-versa. It seems that I'm affecting the ability of JQuery to set focus() on the swapped out id. Here's the code (no closing tags).
For the form Select A Sign lawn signs banners carved signs sandblasted signs Quantity:
the JQuery that swaps the drop down select with the input box which happens on a change of the product id shown above newField either contains on or the other of the following:
newField = "<select id='quantity' name='quantity'><option selected value='10'>10</option><option value='20'>20</option><option value='30'>30</option><option value='40'>40</option>option value='50'>50</option><option value='60'>60</option><option value='70'>70</option><option value='80'>80</option><option value='90'>90</option><option value='100'>100</option></select>";
newField = "<input id='quantity' name='quantity' maxlength='2' size='2' \>"
and the JQuery replaceWith() which will swap out one of the two fields above depending upon another selection drop down box.
$('#quantity').replaceWith($(newField)).attr("id", "quantity");
This all works just fine and the swaps work great except that when I do the following (my test code), nothing happens. No alert is triggered when I focus into the input box.
$('#quantity').focus(function(){
alert ("focused");
});
Am I losing some sort of context on the id with the swap using replaceWith() since the id is the same regardless of whether I swap a select drop down with an input box.
Thanks