/    Sign up×
Community /Pin to ProfileBookmark

creating a function

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

to post a comment
JavaScript

10 Comments(s)

Copy linkTweet thisAlerts:
@fredmvJan 09.2004 — 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:[list=1]
  • [*]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.
  • [/list]
    Copy linkTweet thisAlerts:
    @jiserauthorJan 09.2004 — Hi,

    here's my test-form:

    <form name=idform>

    <input type=text name=id>

    </form>
    Copy linkTweet thisAlerts:
    @PittimannJan 09.2004 — Hi!

    If you use:
    document.idform.id.value = id;[/QUOTE]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) ?
    Copy linkTweet thisAlerts:
    @jiserauthorJan 09.2004 — 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

    [b]function function1() {

    document.idform.id.value = id;}[/b]


    }

    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>
    Copy linkTweet thisAlerts:
    @jiserauthorJan 09.2004 — any ideas?
    Copy linkTweet thisAlerts:
    @KorJan 09.2004 — you have an extra bracket...

    function function1() {

    document.idform.id.value = id;[color=red]}[/color]

    }
    Copy linkTweet thisAlerts:
    @PittimannJan 09.2004 — 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:

    [COLOR=red]}[/COLOR]

    function function1() {

    document.idform.id.value = id;

    }

    Cheers - Pit
    Copy linkTweet thisAlerts:
    @KorJan 09.2004 — Quite confusing fo a rapid glance

    he once use the brackets after an if statemnt, sometimes not....
    Copy linkTweet thisAlerts:
    @clairec666Jan 09.2004 — 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)
    Copy linkTweet thisAlerts:
    @jiserauthorJan 09.2004 — 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
  • ×

    Success!

    Help @jiser spread the word by sharing this article on Twitter...

    Tweet This
    Sign in
    Forgot password?
    Sign in with TwitchSign in with GithubCreate Account
    about: ({
    version: 0.1.9 BETA 6.15,
    whats_new: community page,
    up_next: more Davinci•003 tasks,
    coming_soon: events calendar,
    social: @webDeveloperHQ
    });

    legal: ({
    terms: of use,
    privacy: policy
    });
    changelog: (
    version: 0.1.9,
    notes: added community page

    version: 0.1.8,
    notes: added Davinci•003

    version: 0.1.7,
    notes: upvote answers to bounties

    version: 0.1.6,
    notes: article editor refresh
    )...
    recent_tips: (
    tipper: @nearjob,
    tipped: article
    amount: 1000 SATS,

    tipper: @meenaratha,
    tipped: article
    amount: 1000 SATS,

    tipper: @meenaratha,
    tipped: article
    amount: 1000 SATS,
    )...