goodieboy wrote:
OK I've got the same problem happening again in a different page. I'd
love to know why this is happening before I start re-arranging all of
my html. Anyone know what could be causing this?
No, I don't understand it. This is really odd. I did note that it's in
the regex.replace that this is happening. If you replace this line
var new_name = n.replace(/\[\d?\]/, '[' + OINDEX + ']');
with this one
var new_name = 'product_options[' + OINDEX + ']';
Everything works fine. But I'm assuming that in your real system, you
actually need a replace.
Bizarre.
For anyone who wants to look at them live, I've posted it to
http://scott.sauyet.com/Javascript/Demo/2007-08-24a/Broken/
http://scott.sauyet.com/Javascript/Demo/2007-08-24a/Working/
Any JQuery gurus have suggestions?
Good luck,
-- Scott
On Aug 23, 10:23 pm, goodieboy <[EMAIL PROTECTED]> wrote:
OK, turns out I am crazy, but thanks to html and javascript. So,
depending on the arrangement of the default ".productOption" div, I
either get the behavior you all have described, or the behavior I have
described. Below, if '.productOption' is after the
'#newProductOptions' div, the number doesn't increment. If it's before
'#newProductOptions', wallah!. Wow, a whole 2 days of me rubbing my
forehead raw, and a room booming full of, "wtf f?!?" :-) I'm happy
now.
Try it and see what happens:
<%= javascript_include_tag('jquery') %>
<script>
JQ = $;
var OINDEX=1000;
JQ(function(){
JQ('#addProductOption a').click(function(){
addProductOption();
return false;
});
function addProductOption(){
var tpl = JQ('.productOption:first').clone(true);
JQ(tpl).find('[EMAIL PROTECTED]').each(function(){
var n = JQ(this).attr('name');
var new_name = n.replace(/\[\d?\]/, '[' + OINDEX + ']');
JQ(this).attr('value', new_name);
JQ(this).attr('name', new_name);
});
OINDEX++;
JQ('#newProductOptions').append(tpl);
tpl.show();
}
});
</script>
<div id="addProductOption"><a href="#">add</a></div>
<div id="newProductOptions">
</div>
<!-- down here, OINDEX doesn't increment inside of the "each"
handler... move this div above newProductOptions to get the correct
behavior -->
<div class="productOption">
<input name="product_options[][name]" type="text" value="" />
</div>