Click to See Complete Forum and Search --> : creating a function
jiser
01-08-2004, 07:01 PM
Hello EveryBoDy,
I want to insert this=
document.idform.id.value = id;
into a new function
function function1() {
document.idform.id.value = id;
}
But this is giving a error. (object not denified)
What have I done wrong??
Many Thanx
Jiser
fredmv
01-08-2004, 07:05 PM
We would have to see the HTML form as well as the rest of your JavaScript to accurately help you out. However, it's most likely one of two things: You're trying to print the literal string "id" into the form element but you didn't quote it so JavaScript is trying to find a variable by that name, which doesn't exist, and thus you're getting that error. The form and form element doesn't exist.
jiser
01-08-2004, 07:09 PM
Hi,
here's my test-form:
<form name=idform>
<input type=text name=id>
</form>
Pittimann
01-08-2004, 07:11 PM
Hi!
If you use:
document.idform.id.value = id;you'll need a form in your document with the name "idform" and a formfield with the name "id". You will also need to declare the variable called id and assign avalue to it...
Cheers - Pit
edit: something quite normal - fredmv is very fast (and accurate) :)
jiser
01-08-2004, 07:13 PM
Here's the fully code:
<html>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<SCRIPT LANGUAGE="JavaScript">
<!-- Original: Ronnie T. Moore -->
<!-- Web Site: The JavaScript Source -->
<!-- This script and many more are available free online at -->
<!-- The JavaScript Source!! http://javascript.internet.com -->
<!-- Begin
function readID() {
var expDays = 365; // number of days the cookie should last
var expDate = new Date();
expDate.setTime(expDate.getTime() + (24 * 60 * 60 * 1000 * expDays));
var id = GetCookie('id');
if (id == null || id == "no id") {
if (location.search.length > 1) id = location.search.substring(1, location.search.length);
else id = "no id";
if (id != GetCookie('id')) SetCookie('id', id, expDate);
}
// You can change the FORM location below
// where the referral ID is stored on your page
// You then access this element to get the ID
function function1() {
document.idform.id.value = id;}
}
function getCookieVal (offset) {
var endstr = document.cookie.indexOf (";", offset);
if (endstr == -1)
endstr = document.cookie.length;
return unescape(document.cookie.substring(offset, endstr));
}
function GetCookie (name) {
var arg = name + "=";
var alen = arg.length;
var clen = document.cookie.length;
var i = 0;
while (i < clen) {
var j = i + alen;
if (document.cookie.substring(i, j) == arg)
return getCookieVal (j);
i = document.cookie.indexOf(" ", i) + 1;
if (i == 0) break;
}
return null;
}
function SetCookie (name, value) {
var argv = SetCookie.arguments;
var argc = SetCookie.arguments.length;
var expires = (argc > 2) ? argv[2] : null;
var path = (argc > 3) ? argv[3] : null;
var domain = (argc > 4) ? argv[4] : null;
var secure = (argc > 5) ? argv[5] : false;
document.cookie = name + "=" + escape (value) +
((expires == null) ? "" : ("; expires=" + expires.toGMTString())) +
((path == null) ? "" : ("; path=" + path)) +
((domain == null) ? "" : ("; domain=" + domain)) +
((secure == true) ? "; secure" : "");
}
// End -->
</script>
</head>
<body bgcolor="#FFFFFF" text="#000000">
<SCRIPT LANGUAGE="JavaScript">
// You can change the FORM location below
// where the referral ID is stored on your page
// You then access this element to get the ID
</script>
<form name=idform>
<input type=text name=id>
</form>
</body>
<BODY OnLoad="readID();function1();">
</html>
jiser
01-08-2004, 07:27 PM
any ideas?
you have an extra bracket...
function function1() {
document.idform.id.value = id;}
}
Pittimann
01-09-2004, 05:28 AM
Hi!
Yes, Kor! But to avoid confusion: jiser should not delete it. It belongs to the previous function, so it just has to be moved instead of be deleted:
}
function function1() {
document.idform.id.value = id;
}
Cheers - Pit
Quite confusing fo a rapid glance
he once use the brackets after an if statemnt, sometimes not....
clairec666
01-09-2004, 08:27 AM
Shouldn't everyone use brackets after if/else statements to avoid confusion? And indent the text when they open/close a brakets so you can see what part of the code is contained in a function/if statement etc.? I think dreamweaver does this for you, so you can find a way around your code easier (one reason for using dreamweaver and other coding tools)
jiser
01-09-2004, 08:42 AM
Hi,
Still not working, it says= "id;" object not found. When I don't put it in a function (I inserted it into a function to load in the body handler) there is no problem.
The whole script has to be inserted in the head of my masterscript but document.idform.id.value = id; only in one snippet. Thatswhy I wanted to call document.idform.id.value = id; only in this snippet using the body handler.
Now I found I new solution to fool the browser:
[list] add the whole code into one masterscript add
<form name=idform>
<input type=hidden name=id>
</form>
into the body add </script>
<form name=idform>
<input type=text name=id>
</form> into that one snippet
Thanx about everything
Jiser