I have a table in which there are small href links assigned in each row which i have set using below code working fine:
<h10>(check status)</h10>
Now I do not want to display the same above href link as static but want to send my variable value to the pop window and need to get data displayed separately for each row.
In short i want to pass my variable $name in the popup window. I am trying below code but but isn't happening. Even i tried <FORM> by GET
<?php echo "<h10>(check status)</h10>";?>
On popup.php page:
<?php echo $id = $_GET["id"]; ?>
What i want want is to pass variable using any method (GET or HREF), and it should open in new popup window not in next tab or forwarded window
change this
<?php echo "<h10>(check status)</h10>";?>
to
<?php echo "<a target='_blank' href='popup.php?id=".$name."' onclick=\"window.open(this.href, 'popupwindow', width=400,height=300,scrollbars,resizable');return false;\"><h10>(check status)</h10></a>";?>
^ ^ ^ ^// here was the mistake
You have not concatenated the strings properly and you missed ' for herf attribute.
Use target="_blank" for opening link in new tab or new browser.
Related
I got some rows contains a tag (item name) from while loop, I want if I clicked on one of them a new page appears and that page contains some details about the item which I clicked on(without JavaScript).
I used on-click and could open the new page and get some details, but how to relate it to the clicked item.
Code:
while($package_fetch = $package_query->fetch_array()){
$package_td[] = "
<tr>
<td>".$package_fetch["package_no"]."</td>
<td><a href='../reports/r_package.php?hello=true' target='framename'>".$package_fetch["package_name"]."</a></td>
</tr>";
}
the attribue is target and the value is _blank
<a href='#' target='_blank'>Page</a>
that will open the page in a new window
I think you are mixing things.
Your question seems to be related to html rather than to the server side language you do the loop with.
In addition, it seems you are confusing JavaScript with Java.
Nevertheless, it seems you're looking for the "target" attribute in an anchor element.
I have a PHP/HTML button who was link to
<? echo "Login"; ?>
Now I want change to other link to url www.button.com/index.html I changed the ine as :
<? echo "Login"; ?>
the second url is located on same server in other folder , but click on button not forward to link.
If you do not specify the protocol (e.g. http), the function assumes you want to go to a page on the same domain.
Try something like this:
<?="Login" ?>
Also, why are you using a JavaScript event? You could simplify this a lot by just putting the URL in the href attribute (href="//www.button.com").
I have a span whose content (a record #, eg: 'record12345') is generated via javascript. I want to include that record # in an href.
My goal is :
Link
If I just call the span like so, I get the record # as expected:
<span id="exampleId"></span>
But I can't get it to work inside an href. Here are some things I've tried:
<a href='<?php echo "user/<span id='exampleId'></span>" ; ?>'>Link</a>
<a href='user/<?php echo "<span id='exampleId'></span>" ; ?>'>Link</a>
</span>" ;?>">Link
Link
You don't need all that PHP nonsense.
Put this Javascript somewhere
document.onload = function(){
// Get the inner stuff from the span
var url = document.getElementById('exampleId').innerHTML;
var link = document.getElementById('myLink');
link.setAttribute("href",url);
}
Then assuming your span has the link inside of it, and the <a> tag has an id='myLink' this will work.
Here's a JSFIDDLE...
Using jQuery
$('span').click(function() {
window.location.href="user/"+$(this).attr('id');
});
what you are attempting to do above is inject client side code back into the server script
I am stuck in a problem and in need of support from you guys.
My problem is I want to pass a php variable(dynamically called through database in loop) to another div on the same page without page refresh
//This is a loop
<td><a class="linkright" href="#existingcase?case_id=<?php echo $row_mycases['case_id']; ?>"><?php echo $row_mycases['case_id']; ?></a></td>
//The div which should get the above php variable
<div class="tabright" id="existingcase">
<?php
$c_id = $_GET['case_id'];
echo $c_id;
?>
</div>
//the javascript code for calling divs on the same page
<script>
$(".linkright").click(function(){
$(".tabright").hide();
theDiv = $(this).attr("href");
$(theDiv).slideToggle();
});
</script>
It shows in the url like this index.php#existingcase?case_id=2012001 but never passes the case id to #existingcase. And also #existingcase div does not load either but without passing caseid value, #existingcase loads.
Any suggestions would be great.
I think you want to print clicked case_id in div without page load. To do this, you don't want to pass it using url. you can simply achieve it using javascript.
If your div id existingcase is just change your code like this below.
you are printing that same case_id as a text of anchor tag using $row_mycases['case_id'];. So, you can easily get that text using javascript and you can easily print it in your #existingcasediv.
<td><a class="linkright" href="#existingcase"><?php echo $row_mycases['case_id']; ?></a></td>
I don't know about your other scripts. in .linkright click function place this code like this
$(".linkright").click(function(){
$('#existingcase').text($(this).text()); //if your div id is existingcase it will print your case id.
});
try this code. And let me know the result.
SEE THIS FIDDLE DEMO
UPDATED:
To pass client side value to serverside without page reload, you can use jquery.post() method.
Place this PHP code at the top of your page.
<?php
if (isset($_POST['id'])) {
$caseid = $_POST['id'];
return print_r($caseid);
}
?>
$caseid will contain currently clicked case_id value. So, you can use this $caseid wherever you want in this page. If you click on the another case id, it will update with respect to currently clicked case_id
replace your js with below code,
$(".linkright").click(function () {
$(".tabright").hide();
theDiv = $(this).attr("href");
$(theDiv).slideToggle();
$.post("yourPHPFile.php", { //use your current php file name instead of "yourPHPFile.php"
id: $(this).text()
}, function (caseid) {
$('#existingcase').text(caseid);
});
});
id : $(this).text() means, get the current element .text() and assign it to $_POST variable name of id. It will post to yourPHPFile.php. And you can retrieve that value like $caseid = $_POST['id'];.
In function (caseid) {, caseid contains the value of $caseid. So, only in this code, I assigned $caseid = $_POST['id'];
By this you can directly print clicked case_id text to your #exixtingcase div.
Any values after # are not sent to the server. Since PHP is a server technology you php code will never see the values after #
<a class="linkright" href="#existingcase?case_id=<?php echo $row_mycases['case_id']; ?>">
try doing
<a class="linkright" href="existingcase?case_id=<?php echo $row_mycases['case_id']; ?>">
instead and your php code should fill the div.
In my understanding of your explanation I think you are making a mistake. You are trying to mix Javascript and PHP with out page refresh. This is not possible through your code as PHP is server side and only works on the server. You can't do href within the same page and expect PHP code inside this div to be executed. The PHP code will not be there. You can try "view source" in your browser and check it out.
I think the only way to solve your problem is to make AJAX call using Javascript, get the response and put wherever you want (without refreshing the page)
Hope this helps and excuse my English
EDIT : Here is a working example for making a simple AJAX call using Jquery.
Your table should be some thing like this:
<td>
<a class="linkright" href="#" data-id="<?php echo $row_mycases['case_id']; ?>"><?php echo $row_mycases['case_id']; ?></a>
</td>
You will notice I added "data-id" attribute. We will use this id in our AJAX call. Put this in your JS :
// Create Jquery ajax request
$("a.linkright").click( function() {
$.get("example.php", // Put your php page here
{ case_id : $(this).attr("data-id") }, // Get data, taken from the a tag
function(data) { // Call back function displays the response
$(".tabright").html("<p>" + data + "</p>");
}); // Get
}); // click event
}); // Document Ready
I tested the code and it is working. You will need to customize it to work for you. If all of this AJAX is new to you I suggest these links for you :
http://www.w3schools.com/ajax/default.ASP
http://learn.jquery.com/ajax/
Hi I have a php link which calls a modal popup window which all works fine, the problem i am having is that it doesn't pass the php variable in the link.
the php variable shows in the address bar, but it isn't passing to the modal form.
here is my link
echo "<a href=\"?ip_address='.$ip_address.'#accSettings1\" >Add</a>";
And I am getting the variable like this.
$ip_address = $_GET['ip_address'];
echo "$ip_address";
You need double quotes and not single quotes
<? echo "<a href=\"?ip_address=".$ip_address."#accSettings1\" >Add</a>"; ?>
-^-------------^-
It will pass . and ' as literal string, the output will be something like
Assuming $ip_address = 'hello';
<a href="?ip_address='.hello.'#accSettings1" >Add</a> <!-- HTML Source -->
-^-------^-
This is why the link breaks
so it is adding unnecessary periods and single quotes in the link which breaks it
And the code I provided will be
<a href="?ip_address=hello#accSettings1" >Add</a>