tags:

views:

37

answers:

3

The code works fine when links are images. But I have a problem when there are flash movies. Another page opens with undefined in the address bar when it needs to copy the link id to imagesID input box.

<script type="text/javascript">
var $input = $("#imagesID"); // <-- your input field

$('a.thumb').click(function() {
    var value = $input.val();
    var id = $(this).attr('id');
    if (value.match(id)) {
        value = value.replace(id + ';', '');
    }
    else {
        value += id + ';';
    }
    $input.val(value);
});
</script>
  <ul class="thumbs">
    <li>
        <a class="thumb" id="62">
            <img src="/FLPM/media/images/2A9L1V2X_sm.jpg" alt="Dock" id="62" class="floatLeft" />
        </a>
            <br />

        <a href="?Process=&IMAGEID=62" class="thumb"><span class="floatLeft">DELETE</span></a>
    </li>

    <li>
        <a class="thumb" id="61">
            <img src="/FLPM/media/images/0E7Q9Z0C_sm.jpg" alt="Desert Landscape" id="61" class="floatLeft" />
        </a>
            <br />
        <a href="?Process=&IMAGEID=61" class="thumb"><span class="floatLeft">DELETE</span></a>

    </li>

    <li>
        <a class="thumb" id="60">
            <img src="/FLPM/media/images/8R5D7M8O_sm.jpg" alt="Creek" id="60" class="floatLeft" />
        </a>
            <br />
        <a href="?Process=&IMAGEID=60" class="thumb"><span class="floatLeft">DELETE</span></a>
    </li>
    <li>
        <a class="thumb" id="59">
            <object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://active.macromedia.com/flash4/cabs/swflash.cab#version=4,0,0,0" id="59" width="150" height="100" style="float:left; border:5px solid #CCCCCC; margin:5px 10px 10px 0;">
                <param name="scale" value="exactfit">
                <param name="AllowScriptAccess" value="always" />
                <embed name="name" src="http://www.refinethetaste.com/FLPM/media/flashes/7P4A6K7M.swf"
                quality="high" scale="exactfit" width="150" height="100"
                type="application/x-shockwave-flash"
                AllowScriptAccess="always"
                pluginspage="http://www.macromedia.com/shockwave/download/index.cgi?
                P1_Prod_Version=ShockwaveFlash">
                </embed>
            </object> 
        </a>

            <br />
        <a href="?Process=&IMAGEID=59" class="thumb"><span class="floatLeft">DELETE</span></a>
    </li>
</ul>
A: 

Not all of your a.thumb elements have id attributes, most notably the one associated with the flash object.

Mario Menger
I mistakenly deleted it when I copy pasting it here. Just fixed the code. Please take a look again.
zurna
A: 
  1. You have some links with class "thumb", that don't have an ID or a href, but that will be called from your query code
  2. IDs may not start with an integer
  3. IDs must be unique within the document, which is not the case
harpax
I mistakenly deleted flash movie's href when I copy pasting it here. Just fixed the code. Please take a look again.
zurna
A: 

Have you tried preventing the default browser action?

$('a.thumb').click(function(event) {
        event.preventDefault();
        // ... snip ...
}
Sean Vieira
Sean Vieira, is `event.preventDefault()` different from `return false` somehow? I haven't seen this before and it looks pretty useful :)
macek
Yes and no. No, because when used in a function that is called by an event (`listener` or `on-x`) `return false` has the same effect as `event.preventDefault`. Yes because it provides control of event bubbling without having to return a value. (It's also a jQuery abstraction -- in-browser methods of preventing event execution / bubbling are subtly different.) See: http://en.wikipedia.org/wiki/DOM_events
Sean Vieira