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

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

  1. kheston1

    kheston1 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>
     
    kheston1, Sep 19, 2007
    #1
    1. Advertisements

  2. kheston1

    Evertjan. Guest

    wrote on 19 sep 2007 in comp.lang.javascript:
    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.

    This gives an id TO the created tag,
    does not link to a form with a name,
    even if it were created.
    Same nonsense
    Ancient code,
    use document.getElementById() or document.forms[].elements[]
    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., Sep 19, 2007
    #2
    1. Advertisements

  3. That is a quite ridiculous statement as C# requires ASP.NET which in turn
    relies heavily on client-side JScript support by default.
    Maybe you should let a Web developer do the job?
    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
     
    Thomas 'PointedEars' Lahn, Sep 19, 2007
    #3
  4. kheston1

    kheston1 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
     
    kheston1, Sep 19, 2007
    #4
    1. Advertisements

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.