473,756 Members | 6,970 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

missing name attribute from dynamic input element

I'm attempting to submit a form via a function which dynamically creates a
hidden input:

function submitLocation( theForm) {
var e = document.create Element('input' );
e.setAttribute( 'type', 'hidden');
e.setAttribute( 'name', 'location');
e.setAttribute( 'value', '1');
var f = document.getEle mentById(theFor m);
f.appendChild(e );
document.forms[theForm].submit();
}

The function is called from an anchor's onclick event:

<form name='form1' method='post' action='action. php'>
<a onclick="submit Location('form1 ');">Submit</a>
</form>

However the function produces an input which is missing the name element:

<INPUT type=hidden value=1>

The desired output should be:

<INPUT type=hidden name=location value=1>

Can someone give me a clue? Thanks in advance.
Sep 28 '06 #1
5 2431

Bosconian wrote:
I'm attempting to submit a form via a function which dynamically creates a
hidden input:

function submitLocation( theForm) {
var e = document.create Element('input' );
e.setAttribute( 'type', 'hidden');
e.setAttribute( 'name', 'location');
e.setAttribute( 'value', '1');
var f = document.getEle mentById(theFor m);
f.appendChild(e );
document.forms[theForm].submit();
}
Your code worked for me in IE6. I got a POST with "location = 1". If
it's not working for you, perhaps change "location" to a different
name, just in case somewhere else in your code it's getting mixed up
with window.location ?

Kev

Sep 28 '06 #2
Bosconian said the following on 9/27/2006 10:19 PM:
I'm attempting to submit a form via a function which dynamically creates a
hidden input:

function submitLocation( theForm) {
var e = document.create Element('input' );
e.setAttribute( 'type', 'hidden');
e.setAttribute( 'name', 'location');
e.setAttribute( 'value', '1');
<snip>
Can someone give me a clue? Thanks in advance.
Don't use setAttribute, access the value directly:

e.name="locatio n";

Not sure "e" is a good choice of variable name either.

--
Randy
Chance Favors The Prepared Mind
comp.lang.javas cript FAQ - http://jibbering.com/faq & newsgroup weekly
Javascript Best Practices - http://www.JavascriptToolbox.com/bestpractices/
Sep 28 '06 #3
"Kevin Darling" <kd******@basit .comwrote in message
news:11******** **************@ d34g2000cwd.goo glegroups.com.. .
>
Bosconian wrote:
>I'm attempting to submit a form via a function which dynamically creates
a
hidden input:

function submitLocation( theForm) {
var e = document.create Element('input' );
e.setAttribute( 'type', 'hidden');
e.setAttribute( 'name', 'location');
e.setAttribute( 'value', '1');
var f = document.getEle mentById(theFor m);
f.appendChild(e );
document.forms[theForm].submit();
}

Your code worked for me in IE6. I got a POST with "location = 1". If
it's not working for you, perhaps change "location" to a different
name, just in case somewhere else in your code it's getting mixed up
with window.location ?

Kev
Thanks for your response and testing the code.

I extracted the code from my project and you're right, it does work in both
IE6 and Firefox.

The problem isn't with the syntax, variable names or parameter usage. I
didn't mention that this code is being used with Drupal and somehow the POST
data is being altered. I need to do some more investigating.
Sep 28 '06 #4
"Bosconian" <no****@nowhere .comwrote in message
news:v9******** *************** *******@comcast .com...
"Kevin Darling" <kd******@basit .comwrote in message
news:11******** **************@ d34g2000cwd.goo glegroups.com.. .
>>
Bosconian wrote:
>>I'm attempting to submit a form via a function which dynamically creates
a
hidden input:

function submitLocation( theForm) {
var e = document.create Element('input' );
e.setAttribute( 'type', 'hidden');
e.setAttribute( 'name', 'location');
e.setAttribute( 'value', '1');
var f = document.getEle mentById(theFor m);
f.appendChild(e );
document.forms[theForm].submit();
}

Your code worked for me in IE6. I got a POST with "location = 1". If
it's not working for you, perhaps change "location" to a different
name, just in case somewhere else in your code it's getting mixed up
with window.location ?

Kev

Thanks for your response and testing the code.

I extracted the code from my project and you're right, it does work in
both IE6 and Firefox.

The problem isn't with the syntax, variable names or parameter usage. I
didn't mention that this code is being used with Drupal and somehow the
POST data is being altered. I need to do some more investigating.

I couldn't get Drupal to behave nicely with the aforementioned method (which
works perfectly fine outside of Drupal) and opted instead to simply hardcode
the hidden input into the form and submit the form via an anchor hyperlink
like so:

<code>
<a href='javascrip t:form1.submit( )'>Submit</a>
</code>
Sep 28 '06 #5
Bosconian said the following on 9/28/2006 10:53 AM:

<snip>
>
I couldn't get Drupal to behave nicely with the aforementioned method (which
works perfectly fine outside of Drupal) and opted instead to simply hardcode
the hidden input into the form and submit the form via an anchor hyperlink
like so:

<code>
<a href='javascrip t:form1.submit( )'>Submit</a>
</code>
Oh geez, from bad to worse.

http://jibbering.com/faq/#FAQ4_24

form1.submit() is an IE only coding habit.

If you want to submit a form, just use a submit button.....

--
Randy
Chance Favors The Prepared Mind
comp.lang.javas cript FAQ - http://jibbering.com/faq & newsgroup weekly
Javascript Best Practices - http://www.JavascriptToolbox.com/bestpractices/
Sep 28 '06 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

12
2470
by: CJ | last post by:
Why won't this work? I am passing the name of the form (I have two that use this validation script) but I keep getting an error. Error reads: "document.which_form.name is null or not an object" HTML----------- Form is ----> <form action="thanks.php" method="post" name="contact_form" id="contact_form"> Name -------> <input type="text" name="name" id="name" size="25"> Button sends code -----> <input type="button" value="Submit Form"
4
21298
by: Martin Lucas-Smith | last post by:
I am wanting to know whether are XHTML1-valid characters for use within an id attribute and/or a name attribute. http://validator.w3.org/check?uri=http://www-thaihydro.geog.cam.ac.uk/riverslice/&ss=1&verbose=1 (e.g. see line 77) suggests that it is valid, but the spec suggests that it is not. More detail:
1
2179
by: Jenny | last post by:
Hi, Can I create an array of tags by assigning same name to these tags? For example, I have two <p> tags with the same name t1. But document.all.b.value=document.all.t.length does not work. It works if the tags are <input type=radio...>. This line is OK:
6
2757
by: Joe | last post by:
Hello All: Does anyone know the difference between the name and id attributes in an Html control? I noticed on PostBack that I can not retrieve the Request.Form("id_value") but I can retrieve the Request.From("name_value"). TIA, -- Joe
0
1986
by: Jigar.Patel | last post by:
I have simple remoting server exposing following simple method. When I try to add webreference to this server in another project by serveraddresss?wsdl, it gives me following error: Custom tool error: Unable to import WebService/Schema. Unable to import binding 'MyRemoteObjectBinding' from namespace...
0
4843
by: Jigar.Patel | last post by:
I have simple remoting server exposing following simple method. When I try to add webreference to this server in another project, it gives me following error: Custom tool error: Unable to import WebService/Schema. Unable to import binding 'MyRemoteObjectBinding' from namespace 'http://schemas.microsoft.com/clr/nsassem/RemoteServer/RemoteServer%2C%20Version%3D1.0.0.0%2C%20Culture%3Dneutral%2C%20PublicKeyToken%3Dnull'. Unable to import...
24
2517
by: Chameleon | last post by:
This code does not working in Mozilla. Works fine in IE. -------------- <input type=text value=100 name=textbox> <script> alert(textbox); </script> -------------- This perhaps, because of Microsoft policy to globalize all tag names. Is there any method for cross-browser fix without using getelementbyid?
2
498
by: inventor | last post by:
I'm doing programming for my science prodject, and when I was programming (I'm building an alphebatizer) I ran into this bug: I've got an input box, but no button or output box. so I do some reaserch, insert a button, and when I open it up, instead of the button being added, I lost the input box. Can ANYONE PLEASE HELP ME!!!!!!!!!!!!! I've included a copy of my code as it is: <HTML> <HEAD> Riehl's Alphebatizer <SCRIPT...
1
5757
by: Tomas | last post by:
When I try to load my xslt i get an xml exception with the message "Root element is missing". The stylesheet works when I preview it in stylus studio, but apparently not in my application. Any ideas what may be wrong? The stylesheet: <?xml version="1.0" encoding="utf-8"?> <xsl:transform version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" > <xsl:output indent="yes"/>
0
9487
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9297
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9904
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9884
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9735
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
6556
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5324
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3395
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2697
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.