Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

Open link in new window - target="_blank"

Posted on 2009-04-09
9
768 Views
Last Modified: 2012-05-06
I have a form where I enter a url and it appears on the site as scrolling news.  see www.cluemachines.com (left side).  How do I change the code to have the link open in a new window?
<table border="0" cellpadding="1" cellspacing="1">
     <tr>
      <th>Headline</th>
      <th>Link</th>
      <th>Delete</th>
     </tr>
   <?
   $sql="select * from m_news";
   $res_news=mysql_query($sql);
   while ($res_news_array=mysql_fetch_array($res_news))
    {
     ?>
      <tr>
       <td height="30"><input type="text" name="headline<?echo $res_news_array['id'];?>" value="<?echo $res_news_array['headline'];?>"></td>
       <td><input type="text" name="link<?echo $res_news_array['id'];?>" value="<?echo $res_news_array['link'];?>"></td>
       <td><a onclick="javascript:return deletecheck();" href="admin.php?deletenews=<?echo $res_news_array['id'];?>">Delete</a>
      </tr>
     <?
    }
   ?>
     <tr>
      <td height="30" colspan="2">Add new news:</td>
     </tr>
     <tr>
      <td height="30"><input type="text" name="newheadline" value=""></td>
      <td><input type="text" name="newlink" value=""></td>
     </tr>
     <tr>
      <td height="30" colspan="2"><input type="submit" name="newsformsubmit" value="Update">
     </tr>
    </table>

Open in new window

0
Comment
Question by:livewirewebsolutions
  • 4
  • 3
  • 2
9 Comments
 
LVL 14

Expert Comment

by:shobinsun
ID: 24113215
Hello,

For example:

<a href="http://www.example.com" target="_blank">Example</a>

For more about that:

http://www.w3schools.com/tags/att_a_target.asp

Regards.
0
 

Author Comment

by:livewirewebsolutions
ID: 24113277
Hi,
I am aware of the target="_blank" in simple html.  However, this is dynamic php.  Looking at the code how would I change it so the link opens in a new window?
0
 
LVL 4

Expert Comment

by:bleach77
ID: 24113345
As shobinsun say, just add target="_blank" after the href. As example from one of your code.
  <td height="30"><input type="text" name="headline<?echo $res_news_array['id'];?>" value="<?echo $res_news_array['headline'];?>"></td>
       <td><input type="text" name="link<?echo $res_news_array['id'];?>" value="<?echo $res_news_array['link'];?>"></td>
       <td>
<a onclick="javascript:return deletecheck();" 
href="admin.php?deletenews=<?echo $res_news_array['id'];?>"
target="_blank">Delete</a>
               ^---- Add before this

Open in new window

0
Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
LVL 14

Expert Comment

by:shobinsun
ID: 24113374
Use thhis code:

   <?
   $sql="select * from m_news";
   $res_news=mysql_query($sql);
   while ($res_news_array=mysql_fetch_array($res_news))
    {
     ?>
      <tr>
       <td height="30"><input type="text" name="headline<?echo $res_news_array['id'];?>" value="<?echo $res_news_array['headline'];?>"></td>
       <td><a href="" target="_blank"><?echo $res_news_array['link'];?></a></td>
       <td><a onclick="javascript:return deletecheck();" href="admin.php?deletenews=<?echo $res_news_array['id'];?>">Delete</a>
      </tr>
     <?
    }
   ?>


You should give the apropriate  href value in the above code.

Regards
0
 
LVL 4

Expert Comment

by:bleach77
ID: 24113424
I mislook the probability that you pass the link via post method.

<form action="file.html" method="post" target="_blank">
                add in your form---------^

Open in new window

0
 

Author Comment

by:livewirewebsolutions
ID: 24116315
Hi,

I'm still not understanding exaclty what new code I am supposed to enter.  Also, I need to know exactly where to enter the code in my existing code.  I am the furthest thing from good at PHP.  Please be specific.
Thanks.
0
 
LVL 14

Expert Comment

by:shobinsun
ID: 24128475
Hello,

if you want this:

when clicking on the news links that is displayed from database should open a new window.

then use the code I have pasted above.

 <td><a href="" target="_blank"><?echo $res_news_array['link'];?></a></td>

Regards.
0
 

Author Comment

by:livewirewebsolutions
ID: 24319704
Hi,

I'm still not successful.  Can someone take my existing code, which I have attached again, make the changes, and repost the exact code with the changes highlighted.
<table border="0" cellpadding="1" cellspacing="1">
     <tr>
      <th>Headline</th>
      <th>Link</th>
      <th>Delete</th>
     </tr>
   <?
   $sql="select * from m_news";
   $res_news=mysql_query($sql);
   while ($res_news_array=mysql_fetch_array($res_news))
    {
     ?>
      <tr>
       <td height="30"><input type="text" name="headline<?echo $res_news_array['id'];?>" value="<?echo $res_news_array['headline'];?>"></td>
       <td><input type="text" name="link<?echo $res_news_array['id'];?>" value="<?echo $res_news_array['link'];?>"></td>
       <td><a onclick="javascript:return deletecheck();" href="admin.php?deletenews=<?echo $res_news_array['id'];?>">Delete</a>
      </tr>
     <?
    }
   ?>
     <tr>
      <td height="30" colspan="2">Add new news:</td>
     </tr>
     <tr>
      <td height="30"><input type="text" name="newheadline" value=""></td>
      <td><input type="text" name="newlink" value=""></td>
     </tr>
     <tr>
      <td height="30" colspan="2"><input type="submit" name="newsformsubmit" value="Update">
     </tr>
    </table>

Open in new window

0
 
LVL 14

Accepted Solution

by:
shobinsun earned 250 total points
ID: 24323200
Hi,

Try this code:


<table border="0" cellpadding="1" cellspacing="1">
     <tr>
      <th>Headline</th>
      <th>Link</th>
      <th>Delete</th>
     </tr>
   <?
   $sql="select * from m_news";
   $res_news=mysql_query($sql);
   while ($res_news_array=mysql_fetch_array($res_news))
    {
     ?>
      <tr>
       <td height="30"><input type="text" name="headline<?echo $res_news_array['id'];?>" value="<?echo $res_news_array['headline'];?>"></td>
       <td><a href="" target="_blank"><?echo $res_news_array['link'];?></a></td>
       <td><a onclick="javascript:return deletecheck();" href="admin.php?deletenews=<?echo $res_news_array['id'];?>">Delete</a>
      </tr>
     <?
    }
   ?>
     <tr>
      <td height="30" colspan="2">Add new news:</td>
     </tr>
     <tr>
      <td height="30"><input type="text" name="newheadline" value=""></td>
      <td><input type="text" name="newlink" value=""></td>
     </tr>
     <tr>
      <td height="30" colspan="2"><input type="submit" name="newsformsubmit" value="Update">
     </tr>
    </table>

Open in new window

0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
comma true 6 37
Email called spam 5 36
How to make a good PHP + MySQL + JS pagination system? 3 31
Inserting results of While loop to sql server 5 15
Things That Drive Us Nuts Have you noticed the use of the reCaptcha feature at EE and other web sites?  It wants you to read and retype something that looks like this.Insanity!  It's not EE's fault - that's just the way reCaptcha works.  But it is …
This article discusses four methods for overlaying images in a container on a web page
The viewer will learn how to count occurrences of each item in an array.
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…

856 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question