how to deliver parameters in a anchor url in php - javascript

I want to deliver an id in anchor url, but when i do like this
$<a href="#editEmployeeModal?id=<?php $valeur['idu']" </a>
the anchor stoped working .
all the other information that I found are about a url for another php page.
thanks.

Add echo to output the variable, and close php tag.

Related

Sending/redirecting viewer to URL after receiving form info

I am using a form tied to JS and PHP to capture form info and send it an email address...but I also want to send viewer upon clicking "submit" to be sent to a specific URL...
New to JS and PHP.
Thank you in advance for any assistance.
After sending the email in PHP:
header('location:http://example.com');
also you can use refresh meta tag after sending data:
echo '<META HTTP-EQUIV=Refresh CONTENT="0; URL='www.example.com'">';
In Javascript:
window.location = '/some/page.php';
If you're submitting the form via Javascript. If you're letting the form's action run first, then use the PHP header function:
header('Location: /some/page.php');

How can I load PHP GET values using jquery .load()

I am trying to load data from another page. The data that I am trying to load is simple PHP $_GET value that was passed through a URL
The $_GET value should be loaded only when the following link has been clicked on.
The data only loads when I use the following href link :
<a id="pizza" href="#">Pizza</a>
However when I use this href tag
<a id="pizza" href="menu.php?test_val=1">Pizza</a> <!-- The link is on the same as the menu.php page >
The content does not get loaded. I figured out that it doesn't get loaded because I set the content to display only when the link gets clicked on like so...
<script>
$("#pizza").on("click", function(){
$("#item_description").load("item-details.php");
})
</script>
The problem is when I click on the link it starts a new XHTTP request and doesn't reach the
$("#item_description").load("item-details.php");
Because nothing is being clicked on when there is new XHTTP request.
The item-details page just echo's out the value that was sent
<?php
echo $_GET['test_val'];
?>
Can anyone please help me come up with a solution??
Thanks!!
use
<a id="pizza" href="#">Pizza</a>
to keep your link format and you can use
$("#item_description").load("item-details.php?myvar=1&mysecondvar=2");
to pass your value to your PHP script
you can read GET value by parsing :
window.location.href
if needed

Creating a link to an id that refreshes the page

I am working on a project that uses javascript to make tabs. It has 3 tabs.
Tab three has an id of tab3, what I need is a refresh button that will be on tab3 that will refresh the page. Problem I'm having is if you click on tab3 it will display tab3 data, but it does not change the url. So the refresh button isn't working.
I tried an onclick javascript that reloads the page using location.reload() which reloads the page but not to the tab3. So I put that on a link,
<a href="<?php echo $_SERVER['REQUEST_URI']; ?>#tab3" onclick="reloadPage();" >Refresh</a>
This will link to the correct location, the URL then has #tab3 at the end, then the Javascript runs and it reloads back to the url without the #tab3.
So I then tried this that I saw somewhere.
Go
Which links, but doesn't reload.
What is the best way to do this?
Try this-
<a href="#tab3" onclick="location.reload();" >Refresh</a>
Using window.location is the solution, however if the current location is already the same as the new url that is assigned, then browser will not re-load the page.
The only trick would be to make the new url look "new". This can be done by adding a random identifier as querystring parameter.
In the form:
http://hostname?<dynamic/random>#tab3
Example:
Go
In head put,
<script type='text/javascript'>
function goto(link) {
window.location = link
}
</script>
and do this to your button
<a onclick=goto("<?php echo $_SERVER['REQUEST_URI'] . '#tab3'; ?>"); >GO </a>
if you want to refresh the page and aslo goto same place this code will work
<form method=post action="">
<input type=hidden name=value value="#tab3" />
<input type=submit value=GO />
</form>
<?php
if (isset($_POST['value']))
{
header('Location: http://'. $_SERVER[HTTP_HOST] . $_SERVER[REQUEST_URI] . $_POST["value"]);
}
?>

Why should I click double on an 'a href' attribute to reload the page?

I have such a problem:
When I click on the element the url changes but PHP code doesn't run, but when I click it again or just push 'Enter' in the url, or push F5 the page reloads and PHP code runs
<a href="?action=out" title="Forget me!">
<img src="images/icons/exit.png" id="exit" class="ava">
</a>
Here was my html code.
Here is PHP one:
if($_GET['action']=='out')
{
//do smth. here
}
What is the problem, I just can't get it..
maybe I just have to use JS (location.reload() and so on), but I think that it will be not a good descision...
Thank you in advance!
I believe your href is wrong you have information in the href but no page assigned, if you are sourcing your own page try
<a href="<?php echo $_SERVER['PHP_SELF'].'?action=out'; ?>" title="Forget Me!">

dynamically generating a redirect to an mp3 file with php and javascript

I'm trying to generate the link to the mp3's in my site dynamically using the following code:
<a href="<?php echo "<script language=javascript>location.href='$thisTitle.mp3'</script>";?>" target="_blank" onClick="javascript:PlayerOpen('LFO&#8217;s Revenge',this.href);
return false">Click Me to Hear a Sample</a>
This results in the following url:
http://www.example.com/site/_main_nav/<script language=javascript>location.href='Title 1.mp3'</script>
$thisTitle gets Title 1 from the mysql database.
Do you know how I could fix this? I can't use header('$thisTitle.mp3') because my included header file has already sent the header info which can't be modified. I can't call the included header after this line of code either.
I use the same javascript redirect code in my index file to link to the welcome page:
echo "<script language=javascript>location.href='_main_nav/welcome.php'</script>";
It redirects properly without the javascript code being spat out in the resulting url.
I have the Title 1.mp3 in the _main_nav folder.
change it to
Click Me to Hear a Sample

Categories

Resources