Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 6 of 6

Thread: page content

  1. #1
    New to the CF scene
    Join Date
    Aug 2007
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    page content

    heya all,

    on my website i have a test.php page and link to test.php?test=1 and test.php?test=2
    Code:
         <a href="test.php?test=1">Test 1</a><br>
         <a href="test.php?test=2">Test 2</a><br>
    what javascript script do i need to tell it what to put on these 2 pages (?test=1 and ?test=2) and where to put the content i want to have on these pages.

    can someone please explain?

  • #2
    Master Coder felgall's Avatar
    Join Date
    Sep 2005
    Location
    Sydney, Australia
    Posts
    6,642
    Thanks
    0
    Thanked 649 Times in 639 Posts
    I have information on passing information between web pages using query strings like that along with Javascript at http://javascript.about.com/library/blqs.htm
    Stephen
    Learn Modern JavaScript - http://javascriptexample.net/
    Helping others to solve their computer problem at http://www.felgall.com/

    Don't forget to start your JavaScript code with "use strict"; which makes it easier to find errors in your code.

  • #3
    Senior Coder Arbitrator's Avatar
    Join Date
    Mar 2006
    Location
    Splendora, Texas, United States of America
    Posts
    3,387
    Thanks
    32
    Thanked 288 Times in 282 Posts
    Quote Originally Posted by Matt011 View Post
    what javascript script do i need to tell it what to put on these 2 pages (?test=1 and ?test=2) […]
    Code:
    var d = document;
    var test1 = /(\?|&)test=1/.test(d.URL);
    var test2 = /(\?|&)test=2/.test(d.URL);
    if (!test1 && !test2) {
    	// do something
    }
    else if (test1 && test2) {
    	// do something (error)
    }
    else if (test1) {
    	// do something
    }
    else { // test2
    	// do something
    }
    Quote Originally Posted by Matt011 View Post
    […] and where to put the content i want to have on these pages.
    That depends upon the document. You’re going to have to be significantly more detailed in your issue description to have this answered.

    Quote Originally Posted by felgall View Post
    I have information on passing information between web pages using query strings like that along with Javascript at http://javascript.about.com/library/blqs.htm
    I didn’t read the entire article, but I noticed that it implicitly condones the use of document.write in XHTML documents (compare pages 1 and 3).

    Also noted is use of the non‐standard window.location.search when DOM2 HTML’s document.URL can do the same thing. Unfortunately, this is more verbose.

    Code:
    var d = document;
    if (/\?.{3,}/.test(d.URL)) {
    	var query = d.URL.match(/\?.+/).toString().substring(1);
    	if (/#/.test(query)) {
    		query = query.replace(/#.+/, "");
    	}
    	// do something
    }
    You might want to consider amending the article.
    For every complex problem, there is an answer that is clear, simple, and wrong.

  • #4
    New Coder
    Join Date
    Aug 2007
    Posts
    58
    Thanks
    2
    Thanked 6 Times in 6 Posts
    I don't understand why you need JavaScript to do this, especially when you are using PHP...

    This Excursion-Powered.com tutorial I helped write uses switches in PHP. I recommend that you read the whole thing, then just use the relevant code. If you don't read the whole tutorial you will probably get lost.
    Note: the rar package for the tutorial isn't up to date, I rewrote a fair chunk of the tutorial recently but haven't got the rar back up yet

    Edit: You don't really need to read past the switches, but feel free if you want. I haven't figured out how to do named anchors in Seditio (the content management system we use there) yet.
    Last edited by Blue_Jeans; 09-01-2007 at 05:57 AM.

  • #5
    New to the CF scene
    Join Date
    Aug 2007
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Quote:
    Originally Posted by Matt011 View Post
    […] and where to put the content i want to have on these pages.
    That depends upon the document. You’re going to have to be significantly more detailed in your issue description to have this answered.
    lets say i want to put this (see code) on the test.php?test=1 and the same on test.php?test=2

    Code:
    <div id="Content" align="center">
    <div id="Title" align="center">= TEST =</div>
    <br>
    
     TEST
    	    
       <div id="Bar" align="center"></div>
    </div>
    Last edited by Matt011; 09-02-2007 at 01:40 AM.

  • #6
    Senior Coder Arbitrator's Avatar
    Join Date
    Mar 2006
    Location
    Splendora, Texas, United States of America
    Posts
    3,387
    Thanks
    32
    Thanked 288 Times in 282 Posts
    Quote Originally Posted by Matt011 View Post
    lets say i want to put this (see code) on the test.php?test=1 and the same on test.php?test=2
    That’s not sufficiently descriptive; you’ve left several key details out.

    • What is the content to be inserted?
    • Where should the content be inserted?
    • When should the content be inserted?
    • What is the source code prior to insertion?
    • What is the source code after insertion?
    • What is the difference in effect when the query string contains only test=1, only test=2, both test=1 and test=2, and when there is no query string?
    For every complex problem, there is an answer that is clear, simple, and wrong.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •