1

ok maybe i must put all my code:

<?php
include('header_application.php');
$obj_clean->check_user();
$limit = 10;
if(!isset($_GET['page']))
  $page = 1;
else
$page = $_GET['page'];

$from = (($page * $limit) - $limit);
$msg = "";
if (isset($_GET['unblock']))
{
  $code = $obj_clean->unblockUser($_GET['unblock'],$_GET['code']);
  if ($code == "error")
  {
     $msg = "Could not delete message!";
  }
  else
  {
    $msg = "You have unblocked ".$code;
  }
}

//Get dynamic data required for this page from the database
$users = $obj_clean->getContacts($_SESSION['user_id'], $from, $limit);
$rows = $obj_clean->getContactsCount($_SESSION['user_id']);
include ("header.php");
?>
<div class="innerContainer">
<head>
<script type="text/JavaScript">
function yesnolist(val)
{
 var e = confirm('Do you want to send a free chat request?');
 if (e == true)
 {
    window.location.href = "http://www-rainbowcode-mobi/confirmfreechat.php";
    //window.location('http://www-rainbowcode-mobi/confirmfreechat.php');
    return true;
 }
  else
    return false;
 }     
</script>  
</head>
<span class="headings2">CONTACTS</span>
<?php if (isset($msg) && !empty($msg)) echo "<br/><font color='red'>".$msg."</font>"; ?>
<br/><br/>
<?php
if (count($users) > 0)
{
    echo "<table width='100%' cellpadding='0' cellspacing='0' border='0'>";
    foreach ($users as $user)
    {
        //Breaks the unique code into 3 parts so that the numeric part can be a different colour
        $codeLength = strlen($user['unique_code']);
        $firstPartLength = $codeLength - 5;
        $uniqueCode3 = substr($user['unique_code'], -2);
        $uniqueCode2 = substr($user['unique_code'], -5, 3);
        $uniqueCode1 = substr($user['unique_code'], 0, $firstPartLength);
        echo '<tr>';
        echo '<td>';
        echo '<a class="charcoal_link" style="line-height: 20px;" href="'.ADDRESS.'view_profile.php?id='.$user['profile_id_contact'].'">'.$uniqueCode1.'<span class="pink_text">'.$uniqueCode2.'</span>'.$uniqueCode3.'</a>';
        $requestor_id = $_SESSION['user_id'];
        $profile_id = $user['profile_id_contact'];
        $rel1 = $obj_clean->hasRelation($requestor_id,$profile_id);
        $rel2 = $obj_clean->hasRelation($profile_id,$requestor_id);
        if($rel1 && $rel2) 
        {
          echo "&nbsp;&nbsp;";
          //echo '<a href="confirmfreechat.php?id='.$profile_id.'" onClick="yesnolist()">Free Chat</a>';
          echo '<a href="#" onClick="yesnolist(); return false;">Free Chat</a>';
        }
        echo "</td>";
        echo "</tr>";
    }
    echo "</table>";
}
else
{
    echo "You have no contacts yet";
}
?>
</div>
<?php include("footer.php"); ?>

hope this will help better

5
  • 1
    What errors are you getting in your error console? Why do you have a div element before head? That is not valid. Where does your body tag begin? Commented May 4, 2011 at 9:40
  • Don't know if this is just a in issue of the above example and your actual code is correct, but the last line should be inside a <?php ?> block. Moreover, I quote Pekka: tell us what happens in the error console and write a cleaner test case. Commented May 4, 2011 at 9:41
  • 1
    @Pekka: body element, sir, body element. Tag is not an element. Or is it? Commented May 4, 2011 at 9:44
  • ok maybe i must put all my code: Commented May 4, 2011 at 10:09
  • @HelloiseSmit: Please format it correctly so that other people can read it. Commented May 4, 2011 at 10:40

4 Answers 4

3
<a href="" onClick="yesnolist()">Free Chat</a>

should be:

<a href="#" onClick="yesnolist(); return false;">Free Chat</a>
Sign up to request clarification or add additional context in comments.

1 Comment

(you want to return false regardless of the outcome of the function call so that the click event is cancelled and therefore the page isn't left before your js function is called)
0

try this:

function yesnolist()
{
    if (confirm('Do you want to send a free chat request?'))
        window.location = "http://www-rainbowcode-mobi/confirmfreechat.php";
}

. . .

<a href="#" onClick="yesnolist()">

Comments

0

I'd assume changing the URLs to valid domains might help things, so try:

window.location.href = "http://www.rainbowcode.mobi/confirmfreechat.php";
window.location('http://www.rainbowcode.mobi/confirmfreechat.php');

Comments

0
function yesnolist()
{
  var e = confirm('Do you want to send a free chat request?');

  if (e == true)
  {
    window.location = "http://www-rainbowcode-mobi/confirmfreechat.php";
    return true;
  }
  else
    return false;
}     

and

<label onClick="return yesnolist();">Free Chat</a>

You can not pass onclick event on (a href="") tag because href part redirects the page and after that the javascript redirect part is called.

Or

(a href="#" onclick="return yesnolist();")Free Chat(/a)  

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.