CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 4 of 4
  1. #1
    Join Date
    Sep 2001
    Location
    Montreal Canada
    Posts
    1,080

    Javascript Question

    Hi all,
    I'm working on ASP pages and I need some javascript to be done. I was thinking you might help me out with this :

    here's the problem

    I dynamically add forms to my html page ( search results ) and I need to send the form when the user clicks on the link of the form.

    here's the code I've been working around so far

    Code:
    function FormSubmit(FormToSend)
    {
        var Str;
        Str = "Document."+FormToSend;
        SendingForm = eval(Str);
        SendingForm.submit();
    }
    I'm using a counter for the form name. and send it to the FormSubmit Function. Well as you can expect the eval line doesn't work. it says it expects a ";" and none is missing. Is there a way to get a reference to an object dynamically ?..
    Nicolas Bohemier

  2. #2
    Join Date
    Sep 1999
    Location
    Leeds U.K. (Proud to be Sheffield Born)
    Posts
    202

    try this...

    From where are you calling the FormSubmit function?

    Depending on this, you could use
    onclick="javascript:FormSubmit();" and examine the window.event.srcElement to determine the object which was clicked.

  3. #3
    Join Date
    May 2002
    Location
    India
    Posts
    143
    The only problem with this function is "Document"
    in this expression

    Str = "Document."+FormToSend;

    try this and it will work:

    Str = "document."+FormToSend;

    (note that small 'd' in 'document' here)

    Now the function will be:

    function FormSubmit(FormToSend)
    {
    var Str;
    Str = "document."+FormToSend;
    SendingForm = eval(Str);
    SendingForm.submit();
    }
    Anupam.

  4. #4
    Join Date
    Sep 2001
    Location
    Montreal Canada
    Posts
    1,080
    I found a solution and it's even simpler

    function formSubmit(FormToSend)
    {
    document.all(FormToSend).submit();
    }
    Nicolas Bohemier

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured