javascript - Can a single script be used for two or more Anchor button clicks? -
There are two 'contact select anchor buttons' in my page, "id select alllink" at the top and "select allLinkB" "The bottom of the being as the id. Top scripts are working perfectly using the following script:
& lt; Script type = "text / javascript" & gt; $ (Function () {$ ('# selectallLink'). (Function () {var a = []; var n = $ ("td.title_listing input: checked"); var s = ""; n .each (Function () {a.push (this.value);}); s = a.join (','); if (a.length> gt; 0) this.href = "/D_ContactSeller.aspx? Property = "+ S; else this.href = 'javascript: alert (" select at least one asset to contact! ");'; Return false;});});
Now for an anchor button below me, I tried to place it as 'select allLinkB' and changed the code like this:
& lt; Script type = "text / javascript" & gt; $ (Function () {$ ('# selectallLink, selectLllBinkB) each. (Function () {var a = []; var n = $ ("td.title_listing input: checked"); var s = ""; ........... .....}}
to call the script for both anchor button events There is no easy way to fast and wait for good response. Thanks in advance ...
You have the problem of using controversial javascript to modify Href, and you also have jQuery There is no reason to actually use this method.
this.href = 'javascript: alert ("Select at least one property Instead, you will need more modern event registration methods You should consider using: $ (function () {$ ('#selectAllLink, #selectAllLinkB') click (function (e) {var a = []; $ ( "Td.title_listing input: checked"). Each (function () {a.push (this.value);}); if (a.length) {this.href = "/D_ContactSeller.aspx?property=" + A.join (','); } Else {e.preventDefault (); Warning ("Select at least one asset to contact!"); return false; }}); });
Comments
Post a Comment