#1
  1. No Profile Picture
    krishanu
    Guest
    Devshed Newbie (0 - 499 posts)
    I need to load a page containing a form into my browser and, once loaded, enter values for some of the form's elements and then submit the form.

    My problem is
    a. how do i Wait for a page to be loaded, after setting document.location=<url>?
    b. can i refer to the form elements by the same name as shown in the page source, as displayed by the browser? Or am I better off referring to the elements (and their properties) using relative definitions e.g. forms[0].elements[1] etc.?

    Any help is greatly appreciated. u cud email me directly to krishanu@cyberdude.com.


  2. #2
  3. No Profile Picture
    dahamsta
    Guest
    Devshed Newbie (0 - 499 posts)
    krisahnu,

    Use the onLoad event handler in the BODY of your document:

    <body onLoad="fill_form()">

    Then you could have a script like:

    function fill_form() {
    document.forms[0].element_name.value = "value";
    document.forms[0].element_2.value = "value";
    document.forms[0].element_3.value = "value";
    document.forms[0].submit();
    }

    Cheers,
    adam
  4. #3
  5. No Profile Picture
    krishanu
    Guest
    Devshed Newbie (0 - 499 posts)
    Hi Adam,

    Thanks for your suggestion. My problem is two fold:
    1. The document that contains the form is not "mine". It is already a
    remote URl which contains a from which i need to fillin and submit.
    Hence my question is how do i set the document.location to the url and
    yet execute the onLoad event handler?
    2. Having loaded the url into the document, i can (hopefully) refer to
    the elements using the construct you have indicated. But that is step
    two for me.

    _Krishanu
  6. #4
  7. No Profile Picture
    dahamsta
    Guest
    Devshed Newbie (0 - 499 posts)
    You might be able to do it using frames, but I'm not sure about filling forms from someone else's namespace. JavaScript security might not allow that.

    Also, I don't know if you can check to see if the other page has loaded yet, because you can't access onLoad from their page. Maybe it would be easier to download their page and set one of your own up on the server?

    Anyway, modify the script to something like:

    top.frames[num].forms[num].element.value='value;

    Where frames[num] is the number of the frame. If the frame is the second that shows up in your code, num will be 1, if it's the fifth, num will be 4. Same goes for forms[num], if the form is the second in the other pages code num will be 0. You get can the element by just looking at their source.

    To submit the form:

    top.frames[num].forms[num].submit();

    adam
  8. #5
  9. No Profile Picture
    krishanu
    Guest
    Devshed Newbie (0 - 499 posts)
    >Also, I don't know if you can check to see >if the other page has loaded yet, because >you can't access onLoad from their page.
    Thats exactly the problem. Even with two frames, unless I can wait for the document to be loaded on the other frame, there isn't much that can be done!

    >Maybe it would be easier to download their >page and set one of your own up on the >server?

    Nope, cant do that either- its a Netscape Calendaring server.

    Guess thats a nogo situation. But thanks anyways. I wanted to write a java applet to do the job, but figured I'd have to let javascript pass the cookies to the applet and then worry about parsing the url data stream contents to find out the form elements etc.. I had thought Javascript should be able to do this easily. Obviously I cant see how.

    _Krishanu

  10. #6
  11. No Profile Picture
    webcoder
    Guest
    Devshed Newbie (0 - 499 posts)

    I'll confirm that it can't be done. Interesing idea though. You'd certainly be able to accomplish this if you could modify the document containing the form.
    Think of the horrible possibilities if JS gave people the ability to fill-in and submit somebody else's forms.

    ------------------
    Matthew J. Flynn
    http://webcoder.net

Similar Threads

  1. Replies: 0
    Last Post: February 11th, 2004, 02:56 PM
  2. set time to load a page
    By lokesh_mani in forum PHP Development
    Replies: 3
    Last Post: September 22nd, 2003, 08:08 AM
  3. html page link prints path 3 times in header of php page
    By virtualdavid in forum PHP Development
    Replies: 1
    Last Post: February 20th, 2002, 01:51 PM
  4. waiting 5 secs to load a page
    By adunkey in forum HTML Programming
    Replies: 1
    Last Post: February 6th, 2002, 04:25 PM
  5. how to load a html page whitout click
    By renato in forum PHP Development
    Replies: 3
    Last Post: June 19th, 2001, 03:14 PM

IMN logo majestic logo threadwatch logo seochat tools logo