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

K

kheston1

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>
 
E

Evertjan.

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>
===============================================
 
T

Thomas 'PointedEars' Lahn

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
 
K

kheston1

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
 

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. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,013
Latest member
KatriceSwa

Latest Threads

Top