473,394 Members | 1,787 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

passing params to html-form

Hi folks,

first of all, I'm absolutly new to javascript. I have designed a html-form
and am trying to path parameters with the suffix of i.e.
?Seminartitel=hallowelt in the url.

In the head of the called page I put the following script (I found it some
where, many thanks to him):

<script language="JavaScript">

function GetUrlValue(Entry)
{
urlText=location.search;
fc=urlText.slice(0,1);
if(fc=="?")
{
l=urlText.length;
urlText=urlText.slice(1,l);
ArgSet=urlText.split("&");
for(i=0;i<ArgSet.length;i++)
{
as=ArgSet[i].split("=");
if(as[0]==Entry)
{
return (as[1]);
}
}
return ("");
}
}
</script>

Now, I would like to preset the field Seminar of the form with the value
Seminartitel.

<input type="text" size="40" name="Seminar" value=" ... xxxxxxxx ......">

Many thanks,
Holger Butschek

--
Erstellt mit M2, Operas revolutionärem E-Mail-Modul:
http://www.opera.com/m2/
Jul 23 '05 #1
2 1992
In article <op**************@news.butschek.com>,
Holger Butschek <ho****@butschek.com> wrote:
I have designed a html-form
and am trying to path parameters with the suffix of i.e.
?Seminartitel=hallowelt in the url. .... Now, I would like to preset the field Seminar of the form with the value
Seminartitel.

Try invoking with formfillin.html?Seminartitel=pass

file: formfillin.html

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>Form</title>
<SCRIPT type="text/javascript">
/*

Most folks lower case the first word in the name of
functions and variables.

Using an upper case letter
in the first word is reserved for functions which
initialize class members:
var myCar = new Car("VW");

Anyway, be consistant.

*/
function getUrlValue(entry)
{
/* Without the var, you are declaring this
variable a global variable. */
var urlText=location.search;
var fc=urlText.slice(0,1);
if (fc=="?")
{
var l=urlText.length;
urlText=urlText.slice(1,l);
var argSet=urlText.split("&");
for (var i=0;i<argSet.length;i++)
{
var as=argSet[i].split("=");
if (as[0]==entry)
{
return (as[1]);
}
}

}
/*
Moved null return in case nothing was passed
*/
return ("");
}

/*
Although not part of your question, I have
included a short validation routine.
*/
function validate()
{

var x = document.forms["myForm"];
var submitOK = true;
var messageText =
"What a suprise! Please correct the error in your ways." +
" Please remove the asterisk ( * ) in the field.";
if (x.seminar.value.indexOf("*") >= 0)
{
alert(messageText);
submitOK = false;
}

return submitOK;

}
</script>
</head>
<body>
<p>Retrieve data passed as search value.</p>
<form name="myForm"
action="http://www.natAValidWebAddress.com"
method="POST"
onsubmit="return validate();">

<SCRIPT type="text/javascript">
var input = getUrlValue("Seminartitel");
/*
document.write will paste data into the document
as the document is loaded.
*/
document.write(
"<input type=\"text\" size=\"40\" name=\"seminar\"" +
"value=\"" + input + "\">");
</script>
<p><input type="submit"></p>
</form>
</body>
</html>


This line will show you the generated html plus everything else:
javascript:'<html><head><title>SourceFileListing<\/title><\/head><body><c
ode><ol><li>'+(document.documentElement||document. body).innerHTML.replace
(/&/g,"&amp;").replace(/</g,"&lt;").replace(/%20%20/g,"&nbsp;%20").replac
e(/\r\n/g,"<li>").replace(/\n/g,"<li>").replace(/\r/g,"<li>")+'<\/ol><\/c
ode><\/body><\/html>';

It wrapped! In IE, you can change innerHTML to outerHTML.

Robert
Jul 23 '05 #2
Robert wrote:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
The system identifier (the URL of the DTD) is missing in this declaration.
It should be

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
[...]
<SCRIPT type="text/javascript">
/*

Most folks lower case the first word in the name of
functions and variables.
True.
Using an upper case letter
in the first word is reserved for functions which
initialize class members:
var myCar = new Car("VW");
That is a *constructor*. Using the "new" keyword when calling it, returns
a reference to an object, not to a "class member". There are no classes
in ECMAScript < 4, JavaScript < 2 and JScript < 6, those are languages
implementing only prototype-based inheritance.
Anyway, be consistant.
ACK
<form name="myForm"
A "name" attribute is not required here ...
action="http://www.natAValidWebAddress.com"
method="POST"
onsubmit="return validate();">
.... if you pass a reference to the calling object:

function validate(x)
{
// This is no longer required then:
*// var*x*=*document.forms["myForm"];
...
}
....
onsubmit="return validate(this);">
[...]
document.write(
"<input type=\"text\" size=\"40\" name=\"seminar\"" +
"value=\"" + input + "\">");
Early JavaScript versions, and ECMAScript implementations allow for using
both the " and the ' character to be used as string literal delimiter. To
make use of that makes especially DHTML easier to read and to maintain.
More, some HTML attributes have default values and thus can be omitted:

document.write('<input name="seminar" value="' + input + '" size="40">');
[...]
<p><input type="submit"></p>


This is not a paragraph, use the "div" element instead of the "p" element.
PointedEars
Jul 23 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Tole | last post by:
hi all, i have some doubts in passing variables by references in php. i usually use class blah { function Params( &$params) { $this->params =& $params; } }
10
by: Resant | last post by:
I have a query : Exec 'Select * From Receiving Where Code In (' + @pCode + ')' @pCode will contain more than one string parameter, eg : A1, A2, A3 How can i write that parameters, I try use :...
0
by: Mihaly | last post by:
Hello, i'm using a VC++ com+ object, it's reference in vs .net, this com object have a function that have to params, the interop com object recive Object Params and the original com object say...
2
by: Tobias Olbort | last post by:
Hello, i've a outer function, which takes a params-array as a parameter. I want to pass this array to inner function with a params-array (e. g. string.format). When i've passed an integer to...
1
by: craigkenisston | last post by:
Hi, I'm trying to create a generic function to call stored procedures in a SQL Server database. I'm passing the params, values and the direction of the params in arrays. The function is...
1
by: Darsin | last post by:
Hi all, I am a new programmer to C# and i am having a following problem. I want to make a single method which takes a variable length array and display it contents. i have defined the method as:...
1
by: raf_z | last post by:
Hi, I'm running a website with Asp.NET, and on one of the pages i have a crystal report with 3 user-populated parameters. However, not all params might be selected. Example: Parameters: 1....
12
by: Dennis D. | last post by:
Hello: I want a function to return three variables to the calling procedure: Private Function CalcTimes(ByVal iAddDays as Integer, ByVal iAddHours as Integer, ByVal iAddMins as Integer) As...
2
by: Sike | last post by:
Hi everyone, I've been browsing this and a few other related newsgroups trying to get my head around this problem, and so far all the trails seem to go cold, without an acceptable solution being...
3
by: q-rious | last post by:
Hello All, 1. I would like to pass some variables (x and y below) from Javascript to PHP, process them in PHP, and return some other variables (a abd b) back to Javascript. --(x,y)--...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.