0

I'm pretty new to javascript so please excuse this question if it seems pretty nooby. I am writing an online calendar to book engineer's jobs so we need to be able to look at the calendar whilst looking at and editing individual jobs. After much deliberation I decided the best way to do this is by opening the jobs in a new window using window.open. However, I would like to pass the job id via the url in order to pass it to the new window but for love nor money I can't work it out or find a solution. Here is my code so far

function open_win() 
{
    window.open('job_detail.php', '_blank','toolbar=0,location=no,menubar=0,height=400,width=400,left=200, top=300');

}

<a href="#" onclick="open_win()" ><? echo $row['name']; ?></a>

The $row['name'] is the value of the link and the value I want to pass will be held in $row['id'] or $job_id. I just can't work out where to put it so it passes on.

Any help will be greatly appreciated

1 Answer 1

3

As a parameter?

function open_win(id) {
    window.open('job_detail.php?id=' + id, '_blank','toolbar=0,location=no,menubar=0,height=400,width=400,left=200, top=300');
}
<a href="#" onclick="open_win(<?= $row['id'] ?>)"><? echo $row['name']; ?></a>
Sign up to request clarification or add additional context in comments.

3 Comments

@user1267224 this is the way to do it and then OP can just retrieve the value using $_GET['id'] or $_REQUEST['id'] on the "job_detail.php" page.
Thanks for that, I tried it then then the link wouldn't do anything. I ended up using <a href="#" onclick="window.open('job_detail.php?id=<? echo $row['id']; ?>', '_blank', 'toolbar=0,location=no,menubar=0,height=400,width=400,left=200, top=300')" ><? echo $row['name']; ?></a> which did the trick
@user1267224: Oh, I assumed id was an integer. If it was a string, you'd have needed to put quotes around it. But you got it fixed, so nevermind :)

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.