0

I want to be able to change a specific value of html of my page based on the url of my website. For example, If I want to change the value to 'example' I'd go to mysite.com/page.php?value=example

Is it possible for me to do this without having to set each value in a php include script?

  • If you want to get the value from javascript you can use [this][1]. [1]: http://stackoverflow.com/questions/5448545/how-to-retrieve-get-parameters-from-javascript – MarutiB Apr 03 '13 at 16:23

2 Answers2

3

On your php page, change this:

<p>This is sample text and the word example.</p>

to this:

<p>This is sample text and the word <?php echo $_GET['value']; ?></p>

This will print whatever value comes after ?value= in your URL onto the page.

adamdehaven
  • 5,890
  • 10
  • 61
  • 84
2

You can apply something like this in your jQuery code to check the page name within a given URL, and then change the value of a specific section on that page! No need for PHP, this is all front-end logic.

var urlspot = document.URL.split('/');
if((urlspot[3] == 'pagename')) { 
  $('#content').text('now i want to change my text on this page');
}

And just change the urlspot[x] to the appropriate number based on location in your URL. It doesn't have to be 3. It could be 1, 2, 3, ,4, etc...You have have to play with it.

klewis
  • 7,459
  • 15
  • 58
  • 102