Form will not submit! Non-Jscript programmer needs help.

Discussion in 'Javascript' started by kheston1@centurytel.net, Sep 19, 2007.

  1. Guest

    Hi,

    I'm a ASP C# programmer who never uses javascript and had to try and
    move a couple of functions (written by someone else) from one page to
    another. The functions work fine, but when I copy them over they fail.
    The last message was the the "frm" object did not support the "submit"
    method. The function simply takes input from a text box and builds a
    little form that it submits to a search site. These are the simplest
    things but I can't figure it out - please help! Code is below.
    Thanks!!

    <script type="text/javascript">
    function fnSearchWebstoreDL()
    {
    var frm = document.createElement("<head><META
    name='WebPartPageExpansion'
    content='full'></head><form name='frmSearchFormName'></form>");
    frm.id = "frmSearchFormName";
    frm.method = "GET";
    frm.action = "http://webstore/webstoresupport/simplesearch.aspx";

    var inpt = document.createElement("<input name='SearchFor'>");
    inpt.id = "idSearchString";
    inpt.value = document.all("txtSearchWebstoreDLFor").value;

    frm.appendChild(inpt);
    document.body.appendChild(frm);
    frm.submit();
    }

    </script>

    <body>
    <table>
    <tr>
    <td>
    <label>Webstore Support:</label>
    <input id='Text1' type="text" name="txtSearchWebstoreDLFor"
    size="25"
    onkeypress="if(window.event.keyCode=='13')return(fnSearchWebstoreDL())"/
    >

    </td>
    </tr>
    </table>

    </body>
    , Sep 19, 2007
    #1
    1. Advertising

  2. Evertjan. Guest

    wrote on 19 sep 2007 in comp.lang.javascript:

    > Hi,
    >
    > I'm a ASP C# programmer who never uses javascript and had to try and
    > move a couple of functions (written by someone else) from one page to
    > another. The functions work fine, but when I copy them over they fail.
    > The last message was the the "frm" object did not support the "submit"
    > method. The function simply takes input from a text box and builds a
    > little form that it submits to a search site. These are the simplest
    > things but I can't figure it out - please help! Code is below.
    > Thanks!!
    >
    > <script type="text/javascript">
    > function fnSearchWebstoreDL()
    > {
    > var frm = document.createElement("<head><META
    > name='WebPartPageExpansion'
    > content='full'></head><form name='frmSearchFormName'></form>");


    document.createElement() only creates a tag element,
    does not insert content, I think.

    There probably is no reliable way to add a functioning <meta>,
    after the page is loaded.


    > frm.id = "frmSearchFormName";


    This gives an id TO the created tag,
    does not link to a form with a name,
    even if it were created.

    > frm.method = "GET";
    > frm.action = "http://webstore/webstoresupport/simplesearch.aspx";
    >
    > var inpt = document.createElement("<input name='SearchFor'>");


    Same nonsense

    > inpt.id = "idSearchString";
    > inpt.value = document.all("txtSearchWebstoreDLFor").value;


    Ancient code,
    use document.getElementById() or document.forms[].elements[]

    >
    > frm.appendChild(inpt);
    > document.body.appendChild(frm);
    > frm.submit();
    >}
    >
    > </script>
    >
    > <body>


    > <input id='Text1' type="text" name="txtSearchWebstoreDLFor"
    > size="25"
    > onkeypress="if(window.event.keyCode=='13')return(fnSearchWebstoreDL())"
    > />


    What a crap code, why the return?


    why the />?
    Is this ment to be IE only, btw?

    Try, [not tested]:

    =============================================
    <input type='text' onkeypress = 'fnSearchWebstoreDL(this);'>

    <script type='text/javascript'>
    function fnSearchWebstoreDL(x) {
    if (window.event.keyCode!=13) return;
    var frm = document.createElement('Form');
    // frm.id = 'frmSearchFormName'; // not used
    // frm.method = 'GET'; // default
    frm.action = 'http://webstore/webstoresupport/simplesearch.aspx';

    var inpt = document.createElement('input');
    inpt.name = 'SearchFor';
    inpt.value = x.value;

    frm.appendChild(inpt);
    document.body.appendChild(frm);

    frm.submit();
    }
    </script>
    ===============================================

    or, [not tested]:

    ===============================================
    <input type='text' onkeypress = 'fnSearchWebstoreDL(this);'>

    <script type='text/javascript'>
    function fnSearchWebstoreDL(x) {
    if(window.event.keyCode!=13) return;
    a = 'http://webstore/webstoresupport/simplesearch.aspx';
    window.location.href = a + '?SearchFor=' + x.value;
    }
    </script>
    ===============================================

    or just use a simple html form doing all this stuf,
    [not tested]:

    ===============================================
    <form action = "http://webstore/webstoresupport/simplesearch.aspx">
    <input name ='SearchFor'>
    </form>
    ===============================================


    --
    Evertjan.
    The Netherlands.
    (Please change the x'es to dots in my emailaddress)
    Evertjan., Sep 19, 2007
    #2
    1. Advertising

  3. wrote:
    > I'm a ASP C# programmer who never uses javascript


    That is a quite ridiculous statement as C# requires ASP.NET which in turn
    relies heavily on client-side JScript support by default.

    > and had to try and move a couple of functions (written by someone else)
    > from one page to another. The functions work fine, but when I copy them
    > over they fail.


    OMG.

    > The last message was the the "frm" object did not support the "submit"
    > method. The function simply takes input from a text box and builds a
    > little form that it submits to a search site. These are the simplest
    > things but I can't figure it out - please help!


    Maybe you should let a Web developer do the job?

    > Code is below. Thanks!!
    > <script type="text/javascript">
    > function fnSearchWebstoreDL()
    > {
    > var frm = document.createElement("<head><META
    > name='WebPartPageExpansion'
    > content='full'></head><form name='frmSearchFormName'></form>");


    Although your code is not Valid (see http://validator.w3.org/),
    this is not a J(ava)Script problem. Get informed about the DOM.

    http://www.w3.org/TR/DOM-Level-3-Core/core.html#ID-2141741547
    http://msdn2.microsoft.com/en-us/library/ms536389.aspx


    PointedEars
    --
    realism: HTML 4.01 Strict
    evangelism: XHTML 1.0 Strict
    madness: XHTML 1.1 as application/xhtml+xml
    -- Bjoern Hoehrmann
    Thomas 'PointedEars' Lahn, Sep 19, 2007
    #3
  4. Guest

    Hey Evertjan - thanks a million for the help! I'll try your
    suggestions immediately.

    Thomas - couldn't agree with you more. I'm a hell of a lame
    programmer. Also, you make a very good point about DOM. I do need to
    get more up to speed on that contruct. Thanks for your feedback!

    Keith


    On Sep 19, 4:28 am, Thomas 'PointedEars' Lahn <>
    wrote:
    > wrote:
    > > I'm a ASP C# programmer who never uses javascript

    >
    > That is a quite ridiculous statement as C# requires ASP.NET which in turn
    > relies heavily on client-side JScript support by default.
    >
    > > and had to try and move a couple of functions (written by someone else)
    > > from one page to another. The functions work fine, but when I copy them
    > > over they fail.

    >
    > OMG.
    >
    > > The last message was the the "frm" object did not support the "submit"
    > > method. The function simply takes input from a text box and builds a
    > > little form that it submits to a search site. These are the simplest
    > > things but I can't figure it out - please help!

    >
    > Maybe you should let a Web developer do the job?
    >
    > > Code is below. Thanks!!
    > > <script type="text/javascript">
    > > function fnSearchWebstoreDL()
    > > {
    > > var frm = document.createElement("<head><META
    > > name='WebPartPageExpansion'
    > > content='full'></head><form name='frmSearchFormName'></form>");

    >
    > Although your code is not Valid (seehttp://validator.w3.org/),
    > this is not a J(ava)Script problem. Get informed about the DOM.
    >
    > http://www.w3.org/TR/DOM-Level-3-Co...dn2.microsoft.com/en-us/library/ms536389.aspx
    >
    > PointedEars
    > --
    > realism: HTML 4.01 Strict
    > evangelism: XHTML 1.0 Strict
    > madness: XHTML 1.1 as application/xhtml+xml
    > -- Bjoern Hoehrmann
    , Sep 19, 2007
    #4
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Maxwell2006
    Replies:
    5
    Views:
    2,371
    Steven Cheng[MSFT]
    Mar 7, 2006
  2. John Grogan

    Non Java programmer needs help!!

    John Grogan, Oct 1, 2003, in forum: Java
    Replies:
    2
    Views:
    321
    John Grogan
    Oct 2, 2003
  3. Mark Mitchell

    Non-programmer needs help with PyGTK-2.0.0

    Mark Mitchell, May 28, 2004, in forum: Python
    Replies:
    6
    Views:
    403
    =?ISO-8859-1?Q?Holger_T=FCrk?=
    May 28, 2004
  4. Sridhar R
    Replies:
    0
    Views:
    279
    Sridhar R
    May 28, 2004
  5. Tony Clarke
    Replies:
    0
    Views:
    246
    Tony Clarke
    Jun 28, 2004
Loading...

Share This Page