0

I have a table in one of the column in a row i use a hyperlink with "Edit" where i call a javascript function (which launches a popup-window)

This is one of my table row

    echo "<tr>";
    echo '<td>' . $row['id'] . '</td>';
    echo '<td>' . $row['firstname'] . '</td>';
    echo '<td>' . $row['lastname'] . '</td>';

    echo '<td>'  .
    '<a href=\"javascript:popup_window_show('#sample', { pos : 'window-center', width : '270px' });'>Edit</a>
    . '</td>';

    echo '<td><a href=\"javascript:popup_window_show('#sample', { pos : 'window-center', width : '270px' });'>Edit</a></td>';

I have used two methods for Edit hyperlink, the first has no prob with code but doesn't shows the 'Edit' in the cell.. and the second has some errors with syntax

Below is my Js function in popup-window.js

function popup_window_show(/*selector,*/ args)
{
var pos    = args.pos    ?   args.pos     : null;

if (pos == 'window-center'      ) 
 { x += $(document).scrollLeft()+($(window).width()-obj.width())*1/2; y += $(document).scrollTop()+($(window).height()-obj.height())*1/2; }
}

And also how do i pass row data to the js function (say firstname)

2
  • "Also"? What's the first thing you're asking? What's not working, where are you stuck? Commented May 17, 2014 at 10:58
  • If you use double quotes (") in single quotes ', you don't have to escape them like this \". Commented May 17, 2014 at 10:59

1 Answer 1

1

I have created a JSBin at http://jsbin.com/yafaxuma/3/edit, which demonstrates how to pass the row as an argument to your function.

Also it wasn't clear what the obj reference was to, so I have commented that in the JSBin and also commented how you can debug your function and see what is happening.

I have used jQuery in the JSBin to pass the row as an argument as it looked like you were also using it for obtaining scroll positions on the document.

The JSBin is showing output in the browser console. If you need more adjustments to the code, just provide me some clear idea of what you want to achieve and I can modify the code to demonstrate how to do what you want.

UPDATE to add PHP echo

echo "<tr>";
echo '<td>' . $row['id'] . '</td>';
echo '<td>' . $row['firstname'] . '</td>';
echo '<td>' . $row['lastname'] . '</td>';
echo '<td><a href="#" onclick="javascript:popup_window_show('#sample', { pos: 'window-center', width: '270px', row: $(this).parents('tr') });">Edit</a></td>';
echo "</tr>";

function popup_window_show(selector, args)
{
   var pos = args.pos ? args.pos : null;
   if (pos == 'window-center') 
   { 
     x += $(document).scrollLeft()+($(window).width()-obj.width())*1/2; 
     y += $(document).scrollTop()+($(window).height()-obj.height())*1/2; 
   }

   var row = args.row;
}
Sign up to request clarification or add additional context in comments.

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.