Question

I am using a link button to redirect the page to my desired location with some query string value from Jquery. The Link Button code are as follows:

<td>
            <a id="selectAllLink" class="button" rel="nofollow ibox&width=800&height=400&title=Contact Now"
                href="#" onclick="return (this.href=='#');">Contact Selected</a>
        </td>

And the Jquery which will create/Update link on click event of my link button are as follows:

function CotactSelected() {
    var a = [];
    var n = $("td.title_listing input:checked");
    var s = "";
    n.each(function() {
        a.push($(this).val());
    });
    var s = a.join(',');

    if (s != null) {
        $("@.button#selectAllLink").attr("href", "/D_ContactSeller.aspx?property=" + s);

    }
    else {
        alert("Select atleast one property to contact!");
    }
}

What i wanted to do is it will collect all the comma separated value from check boxes and pass it to the another page with that collected value as query string. On click of that Link Button it should carry all the comma separated values and redirected to the desired page. Kindly help me.. Thanks in Advance.

Was it helpful?

Solution

use this instead of your function CotactSelected

$(function() {
  $('#selectAllLink').each(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 > 0)
      this.href= "/D_ContactSeller.aspx?property=" + s;
    else
      this.href = 'javascript:alert("Select at least one property to contact!");';
    return false;
  });
});

OTHER TIPS

if (s != null) {
  $("@.button#selectAllLink").attr("href", "");
  $("@.button#selectAllLink").attr("href", "/D_ContactSeller.aspx?property=" + s);
}
else {
    alert("Select atleast one property to contact!");
}

Hope this helps :)

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top