Jump to content

Recommended Posts

I don't know what forum to put this in, but I never had a problem until ajax with this. I have this line:

 

echo '<td><a href="index.php?rtyp=music&id='.$showinfo['id'].'">'.$showinfo['title'].'</a>  ::  <span class="poster">';

 

and i want to change the link to

<a href="javascript:;" onclick = "getData('index.php?rtyp=music&id='.$showinfo['id'].'', 'targetDiv')">

but all the quotes makes this seem impossible. i tried removing the echo, ending the php and then

index.php?rtyp=music&id= <?php $showinfo['id'] ?>, '...

but then the script didn't see the id?

 

Thanks.

Link to comment
https://forums.phpfreaks.com/topic/135580-solved-quotes-driving-me-crazy/
Share on other sites

And this:

cho '<td><a href="javascript:;" onClick="index.php?rtyp=music&id='.$showinfo['id'].'", "targetDiv">'.$showinfo['title'].'</a>  ::  <span class="poster">';

 

which makes the most sense to me doesn't do anything at all.

It goes like this:
echo '<td><a href="javascript:void(0);" onclick="getData(\'music\',\''.$showinfo['id'].'\',\'targetDiv\')" >'.$showinfo['title'].'</a>  ::  <span class="poster">';

(you need to escape the quotes inside the function (javascript wants them as strings) since you're using single quotes as your php boundaries)

 

Create a javascript function, here named showPoster().  The first argument is the rtype, the second is the $showinfo['id'], the third is the target div.  Have the function do whatever you're trying to do, with that info.

 

 

And this:

cho '<td><a href="javascript:;" onClick="index.php?rtyp=music&id='.$showinfo['id'].'", "targetDiv">'.$showinfo['title'].'</a>  ::  <span class="poster">';

 

which makes the most sense to me doesn't do anything at all.

It goes like this:
echo '<td><a href="javascript:void(0);" onclick="getData(\'music\',\''.$showinfo['id'].'\',\'targetDiv\')" >'.$showinfo['title'].'</a>  ::  <span class="poster">';

(you need to escape the quotes inside the function (javascript wants them as strings) since you're using single quotes as your php boundaries)

 

Create a javascript function, here named showPoster().  The first argument is the rtype, the second is the $showinfo['id'], the third is the target div.  Have the function do whatever you're trying to do, with that info.

 

 

 

This still does nothing. I think this is where the AJAX problem comes into play. This page that I'm trying to display these links is called with ajax from another page.

<a href="javascript:;" onclick = "getData('musicrev.php', 'targetDiv')">

Now I guess maybe it doesn't see the targetDiv anymore?

 

For reference it goes like indexpage--(ajax)-->review index--(ajax not working)-->review

what is in $showinfo['id']...is that 'rev'?

 

try this:

echo '<td><a href="javascript:void(0);" onclick="getData(\'music'.$showinfo['id'].'.php\',\'targetDiv\')" >'.$showinfo['title'].'</a>  ::  <span class="poster">';

 

if that doesn't work, do a view source on the page, copy/paste what it looks like AFTER php has done it's work...then post what it SHOULD look like

doesn't work. It gives:

<a href="index.php?rtyp=music&id=203">Woven - Designer Codes Tour</a>

 

after the php does its work which is the link i want to open in targetDiv but when I click on the actual link it doesn't work.

 

I don't get it.

 

what is in $showinfo['id']...is that 'rev'?

just the id of the sql entry for the review

Reference: http://thehyp.net/reviews/

 

Ok, so people go to our reviews page. There is a sub-menu for the different review pages:

<!-- Begin Submenu -->
<table id="Table_01" width="431" border=0 cellpadding="0" cellspacing="0" class="revsub">
      <tr>
        <td><a href="index.php"><img src="../images/reviewsub_01.png" alt="reviews" width="100" height="42" border=0 id="reviewsub_01" /></a></td>

        <td><a href="javascript:;" onclick = "getData('musicrev.php', 'targetDiv')"><img src="../images/reviewsub_02.png" alt="music reviews" width="76" height="42" border=0 id="reviewsub_02" /></td>
        <td><a href="javascript:;" onclick = "getData('gamesrev.php', 'targetDiv')"><img src="../images/reviewsub_03.png" alt="game reviews" width="66" height="42" border=0 id="reviewsub_03" /></a></td>
        <td><a href="javascript:;" onclick = "getData('fdrev.php', 'targetDiv')"><img src="../images/reviewsub_04.png" alt="food and drink reviews" width="108" height="42" border=0 id="reviewsub_04" /></a></td>
        <td><a href="javascript:;" onclick = "getData('otherrev.php', 'targetDiv')"><img src="../images/reviewsub_05.png" alt="other reviews" width="81" height="42" border=0 id="reviewsub_05" /></a></td>
      </tr>
    </table>
<!-- End Submenu -->	

<table width="100%" border=0>
<tr>
<td valign="top" width="80%" class="news">


<!-- Insert PHP Generaged tables here -->
<div id="targetDiv">	
...

 

as you can see the sub-menu loads the page into the target div. No problem.

 

So the person clicks on the music link, it loads musicrev.php into targetDiv... work great but then I tried to make the concert links ajax and have them load in the targetDiv. Using the link code you suggested the link just simply does nothing.

 

I hope that clarified, I've been having a hard time wording this problem.

Thanks for all the help! I'll try to figure out what exactly happened and I'm sure I'll have to since I'm going to change all the pages to ajax now.

 

is there a specific reason you are loading all the content via AJAX? by doing it this way, search engines can't parse your content, users can't use the back button, and if they have javascript disabled, your site won't work.

Thanks for all the help! I'll try to figure out what exactly happened and I'm sure I'll have to since I'm going to change all the pages to ajax now.

 

is there a specific reason you are loading all the content via AJAX? by doing it this way, search engines can't parse your content, users can't use the back button, and if they have javascript disabled, your site won't work.

 

I figured it'd be smoother, we have the big content heavy header and submenus so i figured not having them reload all the time would be a lot better for browsing. I also only learn by trying to implement examples into my own work and then failing repeatedly and getting you guys to help me. Do you recommend I de-ajax this then?

Thanks for all the help! I'll try to figure out what exactly happened and I'm sure I'll have to since I'm going to change all the pages to ajax now.

 

is there a specific reason you are loading all the content via AJAX? by doing it this way, search engines can't parse your content, users can't use the back button, and if they have javascript disabled, your site won't work.

 

I figured it'd be smoother, we have the big content heavy header and submenus so i figured not having them reload all the time would be a lot better for browsing. I also only learn by trying to implement examples into my own work and then failing repeatedly and getting you guys to help me. Do you recommend I de-ajax this then?

 

that is a call you have to make. normally, i try to make my sites work without javascript/ajax. then spice it up after. for example, with your A tags, put the URL in the href, so search engines and people with javascript can use them, but if javascript is available, load it with ajax:

<td><a href="musicrev.php" onclick = "getData('musicrev.php?mode=ajax', 'targetDiv');return false;"><img src="../images/reviewsub_02.png" alt="music reviews" width="76" height="42" border=0 id="reviewsub_02" /></td>

 

-the 'return false;' will prevent the <a> tag from doing it's normal function of navigating to musicrev.php.

-the ?mode=ajax portion is so on musicrev.php you know to print the header/footer or just the content. default, print the entire page, if mode=ajax, only print the center content

 

as for facebook, they use javascript trickery to utilize the backbutton. here is an example i just found in a google search:

http://www.contentwithstyle.co.uk/content/fixing-the-back-button-and-enabling-bookmarking-for-ajax-apps

 

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.