0

I have small project in which i have different news. And i am giving every news a div id.Please check the demo here:enter link description here. In current page i have shown only small portion of news.And when you click on this news then another page should open which will show the complete news on which you click. So i have used javascript to take the id to identify each individual news. And its working fine for me. But now i want to pass this id in url so that i can take this id and show the complete news in another page. It should be look like this: complete_news.php?id= . I am trying to do the same thing but now working.Any help.Thanks. Here is my code: Html Code

<table width="538" cellpadding="0" cellspacing="0" border="1">
<a href="complete_news.php?id=" class="TrackClick" id="01">
<div class="welcome-rahmen lng toggleNews" id="news_269_kurz">
<p class="welcome-breadcrump">Montag, 19.05.2014</p>
<p class="welcome-subheadline">Teilnahme von MAN Top Used an der Samoter 2014</p>
<div class="newsText">
<p class="welcome-text"><img src="http://intern.autodo.de/admin/news/man-it.jpg" width="165" class="text_fixed" border="0"></p>
<p class="welcome-text">Die 29. Internationale Erd- und Bautechnik-Ausstellung Samoter fand zwischen dem 8. und 11. Mai in Verona statt und zog rund 100.000 Besucher an. Samoter ist die wichtigste italienische Messe ihrer Art, die den Themen Erdbewegung, Hochbau und Baumaschinen gewidmet ist. Zugleich ist diese Veranstaltung damit auch f? europ?chen Markt bedeutsam.</p>
</div>
</div>
</a>
</table

<table width="538" cellpadding="0" cellspacing="0" border="1">
   <a href="complete_news.php=id=" class="TrackClick" id="02">
<div class="welcome-rahmen lng toggleNews" id="news_264_kurz">
<p class="welcome-breadcrump">Freitag, 24.01.2014</p>
<p class="welcome-subheadline">Kaufvertrag: neue Porsche-Vorlage zum Drucken!</p>
<div class="newsText">
<img src="http://intern.autodo.de/admin/news/porsche-kaufvertrag.jpg" border="0" align="right" class="img_fixed" width=60><p class="welcome-text">Ihr AMO Druckcenter bietet Ihnen ab sofort die M?chkeit, Kaufvertr? im Porsche-Design zu nutzen.</p>
<p class="page-breadcrump">AutoDo!-Team</p>
</div>
</div>
</a>
 </table> 

Javascript Code:

$(function() {
      $('.TrackClick').click( function() {
            var $this = $(this);
            var href = $this.attr('href');
            window.open(href,'','width=650,height=400,scrollbars=yes,left=150,top=100,screenX=150,screenY=100');
            alert( $this.attr('id') );
            return false;
      });
 });    
user3702602
  • 139
  • 3
  • 16

4 Answers4

1

you need to do like this:

var href = $this.attr('href');
href += $(this).attr("id");

or:

var href = $this.attr('href')+$(this).attr("id");

FIDDLE DEMO

Ehsan Sajjad
  • 61,834
  • 16
  • 105
  • 160
1

You have to correct the href as below:

var href = $this.attr('href')+$this.attr('id');
kcak11
  • 832
  • 7
  • 19
  • And i think working with Ajax also be a soltuion and gives better performance right ? – user3702602 Jun 05 '14 at 07:08
  • Would you please accept the answer as correct, in case it worked for you. Regarding your question, I think it is related to PHP, so not sure about that. – kcak11 Jun 05 '14 at 07:09
1
<a href="complete_news.php=id=" class="TrackClick" id="02">

should be

<a href="complete_news.php?id=" class="TrackClick" id="02">

then

$(function() {
  $('.TrackClick').click( function() {
        var $this = $(this);
        var href = $this.attr('href')+$this.attr('id');
        window.open(href,'','width=650,height=400,scrollbars=yes,left=150,top=100,screenX=150,screenY=100');
        alert( $this.attr('id') );
        return false;
  });
 });   
T J
  • 42,762
  • 13
  • 83
  • 138
  • How is it different from my answer ? – kcak11 Jun 05 '14 at 07:07
  • Thanks everyone its working now. I have just one more question. Can i take this id like: $ID=$_GET['id']; in complete_news.php page ? So that i can take this id and use if condition to get every news. And i think working with Ajax also be a soltuion and gives better performance right ? – user3702602 Jun 05 '14 at 07:09
  • check [this](http://stackoverflow.com/questions/8469767/get-url-query-string) or [this](http://stackoverflow.com/questions/4656843/jquery-get-querystring-from-url) – T J Jun 05 '14 at 07:11
0

Here is the answer as per solution :

$(function() {
      $('.TrackClick').click( function() {
            var $this = $(this);
            var href = $this.attr('href');
            href += $(this).attr("id");
            window.open(href,'','width=650,height=400,scrollbars=yes,left=150,top=100,screenX=150,screenY=100');
            alert( $this.attr('id') );
            return false;
      });
 }); 
user3702602
  • 139
  • 3
  • 16