HTML - How to add a variable?

Hello,

I am new to HTML :
I have built my website from several html pages. Each html page includes a form.
Each form defined like this:
<form class="MyForm" method="get" action="http://172.1.1.5/cgi-bin/start">

I want to set the action as a parameter/const outside my pages, and to read this parameter from some place. Because if tomorrow I decide to change the action to be "http://155.5.5.5/cgi-bin"  I should go to each page and change it their. Instead I want to change this parameter on one place only.
How can I do it?

THANKS
margaritAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

xBelloxCommented:
you can save your action URL (http://172.1.1.5/cgi-bin/start)  as a normal text file named: "action.include" or anything else.


And in your HTML forms you write this:

<form class="MyForm" method="get" action="<!--#include virtual="action.include" -->">

Open in new window

0
ZylochCommented:
Off the top of my head there are 3 solutions,

1) If all your forms are the same, you can include it in a single HTML page that is called by an iframe. You can even make the iframe look like part of the page with appropriate CSS styles.

2) You can employ a server-side language, such as PHP, which will print out the HTML for you, substituting a variable that you define elsewhere in a file included in your PHP pages for the form action.

3) You can finagle your way around it by setting the form action from an external JavaScript file. This would  work for all browsers that have JavaScript enabled, but because of that unnecessary precondition given the other two solutions, I do not recommend it.

Let us know if you need any clarification on any of these.
0
ajkhalifaCommented:
It is always better to use server side programming language for that such as PHP, ASP, ASP.NET, JSP ... etc.
but if you are only in html environment, you can use javascript...
create a dot js file and define a variable say and make a change action function like this:
-------------------------------------------------------------------
var v='http://myip/a.asp';
function changeAction(){
      document.form5.action=v;
}
--------------------------------------------------------------------

and then in your code make it like this:


------------------------------------------------------------------------
<html>
<head>
<script src="myjsfile.js" type="text/javascript"></script>
</head>
<body onload="changeAction();">
<form name="form5" method="post">
<input type="submit">
</form>
</body>
</html>
------------------------------------------------------------------------
0
Determine the Perfect Price for Your IT Services

Do you wonder if your IT business is truly profitable or if you should raise your prices? Learn how to calculate your overhead burden with our free interactive tool and use it to determine the right price for your IT services. Download your free eBook now!

margaritAuthor Commented:
Hello,
Thanks for helpful comments!!!
xBellox:
How should I put (define) URL in my text file? Can you please give me an example? And If I want to add several parameters to one text file, can I do it?
ajkhalifa:
I can put these way several scripts to one external file? What is a diffrence between methods "get" & "host". I read in the web but did not understand.
Zyloch:
Can you explain me the second solution in more details? Maybe you can give me an example.
THANKS
Margarit
0
ZylochCommented:
First, in xBellox's solution, a server side include (SSI) is used. Your server or web host needs to support server side includes for it to work. I believe, if it does, you can just put your form action URL in a file called action.include by itself. I don't exactly remember the difference between virtual and file, but you can look that up to find out where to place the file -- probably in the same directly as your HTML.

Second, the two form methods GET and POST are both used to transmit information from a form submit. A get request will show up in the URL as a query string. For example, http://www.google.com/search?hl=en&q=test&aq=f&oq=&aqi=g10 is a Google search that is passed from a GET form -- note the key=value pairs after the question mark. POST on the other hand passes information that does not appear in the URL and essentially must be submitted from the form instead of merely entered into the URL (this is not exactly true, but it's good enough for now). The most important thing you should remember perhaps is that GET has a limit on how much form information can be passed, and POST practically does not.

Finally, my second solution is similar to the solution involving SSI in the sense that it requires your server or web host to support a server side language like PHP (or ASP or JSP). If it supports PHP, you could write into yourpage.php:

<?php
$form_action = 'blah blah.php';
?>
// All your HTML
<form action="<?php echo $form_action; ?>">

Of course, this is not so useful unless  you put the URL in a third file and include it in this file with PHP, that's possible, of course, but it would be pointless to give it to you if you can't employ this solution. Let us know your situation.
0
margaritAuthor Commented:
Hi,
THANKS for  the explanations! They are very helpful!
My server supports Java script. If I understand right.
I create file "myDefinitions.js":
Inside I put the following:
<?js
$form_action = "http://170.1.1.5.js';
?>
 And in my HTML:
<form action="<?js echo $form_action; ?>">
Is my syntax correct?
How does my form know to find form_action variable in  "myDefinitions.js" file?
THANKS
Margarit
 
 
 
 
0
xBelloxCommented:
Create a new document text, write your action URL as normal text like:

http://172.1.1.5/cgi-bin/start

And save it with any name in same directory of your HTML file.

Then in your HTML files, at your form declaration just "include" the file with URL name.

For example, suppose you save your file with the name "action.txt", your form will be like this

<form class="MyForm" method="get" action="<!--#include virtual="action.txt" -->">

Then the brower will understand it and load the file action.txt, so it will equivalent to  this:

<form class="MyForm" method="get" action="http://172.1.1.5/cgi-bin/start">

It occurs because the command <!--#include virtual="action.txt" --> makes the browser read all content of the file action.txt and put it in code.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
margaritAuthor Commented:
THANKS I will try it.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
HTML

From novice to tech pro — start learning today.