#1
  1. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jan 2001
    Posts
    30
    Rep Power
    14

    Unhappy Javascript problem


    Hello there.....

    I am trying to produce an application where the user
    will be able to specify the file in the server where he
    want to store some data. Now if the user selects an
    existing file, the cgi at the server should be able to detect
    that and should give the user a warning message.

    Now I am doing the thing in the following way.
    When the user writes the name of the file and
    submits the form, the cgi script in perl detects
    whether it is an existing one and sends a
    confirm('overwrite') if the file exists already.
    Depending on the user's choice to overwrite
    or not the form is either submitted or not.

    At present I made the confirm dialog box to appear
    when the second page was getting loaded using
    the onLoad. But then if I use form.submit in the javascript
    function, it is not getting submitted because I had not started
    the form.
    Here is the javascript function that I use on the second page.
    function test(form,file,exists)
    {
    var exists =String(exists);
    var file =String(file);
    if (exists =='yes')
    {
    answer =confirm('Overwrite existing file');
    answer =String(answer);
    if (answer == 'true')
    {
    form.filename.value =file;
    form.overwrite.value ='yes';
    form.submit();
    }
    }
    }

    Is there a way to solve my problem.
    Am I doing things in the right way or is there any other better
    way to solve my problem

    I have one more doubt. Is it possible to load a page based one
    some condition.
    Is it possible to call a function when a hidden element in the
    form is changed.
    Could anyone please help...
    Thanks ..
    Dups
    Last edited by Dups; June 7th, 2001 at 02:18 AM.
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    May 2001
    Location
    The Netherlands
    Posts
    200
    Rep Power
    14

    No specific answer


    I can't quite understand the problem, but there are a few things I want to comment on:

    (correct me if I'm wrong)
    1. The onLoad event is triggered after the page has finished loading.
    2. The confirm function returns a boolean. No need to convert the result to a string first. Just do: if (confirm(...)) { ... }

    Question: how do you know that your submit function does not work? Do you get an error? Have you tried putting an alert right in front of your submit just to see if the code actually gets there?

    You also asked:
    "Is it possible to call a function when a hidden element in the
    form is changed."
    It is only possible to change a hidden element through a function. So you are already in a function and you can call any other function you want

IMN logo majestic logo threadwatch logo seochat tools logo