views:

450

answers:

2

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.

A: 

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 help :)

chirag
I was doing that only.But it is still not working.Is there something i am missing out?
Sanju
please remove this codeonclick="return (this.href=='#');"i think it cause a problem.
chirag
What should i try instead of onclick="return (this.href=='#');
Sanju
when u click on this link first time then it will return true on click event,after changing the href value when u click on link then your java script return (this.href=='#') will return false, so it won't work so try it
chirag
It's not working, actually the frame opens mentioning Loading... and no url changes. The problem is page is not redirected.
Sanju
A: 

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;
  });
});
kara
I want to use Anchor Link Button Click event not location.href. So let me know whether is there easy solution is available or not?
Sanju
I did some minor changes, how about now?
kara
Yes now it's working. Thanks a lot Kara...
Sanju
You're welcome!
kara