...

View Full Version : How do I Get the Current Server URL & Path?



dealmaker
12-19-2005, 08:38 AM
Hi,
I am writing a javascript function that insert html code into innerHTML. It's a form, and I need to assign the path of the server file into the <form action="....">. I don't want to hard code the path. How do I use javascript to do it for me? In php, I can user the $_SERVER variable, what about javascript?



function create_form(id) {
var output = "<form action=\"....\".................;
document.getElementById(id).innerHTML = output;
}

Many thanks.

glenngv
12-19-2005, 08:59 AM
You can embed php script inside javascript:

var output = '<form action="<? $_SERVER ?>" method="post">';
or use javascript:

var output = '<form action="' + location.pathname + '" method="post">';
But if you don't specify the form action, the default action page is the current URL. So you can leave the action empty or not specify the action attribute at all.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum