Consider this : www.yourdomain.com/page.html?sometext I want to put a script which will assign the text next to the ? to a variable so that I can use it in the same page. Uses:I can add a person's name to a link and send it to him. When he clicks that link, the page will show a greeting message. Eg: www.mydomain.com/page.html?Lokesh . Clicking or typing it into address bar will take to webpage where "Hi Lokesh" will be mentioned using document.write . If no text or ? is there means the visitor will see "Hi Guest" Any Ideas how to do this?
Try this: www.yourdomain.com/page.php?name=sometext Then at the top of page.php put this: <?php $name = htmlspecialchars($_GET['name']); ?> PHP: Then to display the name, do this: Hello <?php echo "$name"; ?> PHP: Hope that helps. Tim
In ASP or ASP.Net, you can get the value after ? (Query String), using Request.QueryString("name") method. Eg: Your url is like this yourdomain/greetings.aspx?name=John In the greetings.aspx pages's load event, you can write the code for printing the name as follows document.write("Hi " + Request.QueryString("name"')); Thanks SpiceMint
Thank You BigTime.. I will definitely try it.. But the problem I'm having is I dont know anything about PHP. But I can understand the CODE you have provided. Can I use HTML in a PHP file? I will learn a bit of PHP and will try it. so echo is similar to document.write in JS. Thank You SpiceMint.. I dont Know ASP also.. I will try your CODE also.. Can it be done with HTML and JavaScript? As i'm a bit familiar with these.. If a direct function for this is not available in Javascript means I can try a long route. Is there any thing like document.path or similar to assign the whole text that appears in address bar and then write a script to take the part of the string which is next to "?" So PHP and ASP has many more advantages.. I will learn at least some basics of them... Please tell me if any JS alternative is found.. Thanks a lot once again..