473,394 Members | 1,506 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

changing the value of a hidden field

I have a hidden field as such:

<INPUT TYPE=\"hidden\" name=xmlfield >

I have a button that i want to use to call a function to change the value:

<INPUT TYPE=submit VALUE="Display XML" Name="displayXML"
OnClick="ChangeFieldName('XML')">

here is the function

function ChangeFieldName (val) {
document.FieldName.xmlfield.value=val;};

nothing happens? The value is not set?
Jul 23 '05 #1
8 6297
"Ryan" <rg******@comcast.netnospam> wrote in message
news:dc********************@comcast.com...
I have a hidden field as such:

<INPUT TYPE=\"hidden\" name=xmlfield >

I have a button that i want to use to call a function to change the value:

<INPUT TYPE=submit VALUE="Display XML" Name="displayXML"
OnClick="ChangeFieldName('XML')">

here is the function

function ChangeFieldName (val) {
document.FieldName.xmlfield.value=val;};

nothing happens? The value is not set?


function ChangeFieldName (val) {
if( document.getElementById )
document.getElementById('xmlfield').value = val;
}

--
Dag
5826'15.9" N 00846'45.5" E
Jul 23 '05 #2
why do i need:

if( document.getElementById )
?
"Dag Sunde" <ds@orion.no-way> wrote in message
news:cl*******************@juliett.dax.net...
"Ryan" <rg******@comcast.netnospam> wrote in message
news:dc********************@comcast.com...
I have a hidden field as such:

<INPUT TYPE=\"hidden\" name=xmlfield >

I have a button that i want to use to call a function to change the value:
<INPUT TYPE=submit VALUE="Display XML" Name="displayXML"
OnClick="ChangeFieldName('XML')">

here is the function

function ChangeFieldName (val) {
document.FieldName.xmlfield.value=val;};

nothing happens? The value is not set?


function ChangeFieldName (val) {
if( document.getElementById )
document.getElementById('xmlfield').value = val;
}

--
Dag
5826'15.9" N 00846'45.5" E

Jul 23 '05 #3
Ryan wrote:
I have a hidden field as such:

<INPUT TYPE=\"hidden\" name=xmlfield >

I have a button that i want to use to call a function to change the
value:

<INPUT TYPE=submit VALUE="Display XML" Name="displayXML"
OnClick="ChangeFieldName('XML')">

here is the function

function ChangeFieldName (val) {
document.FieldName.xmlfield.value=val;};

nothing happens? The value is not set?


Use document.FORMNAME instead of document.FIELDNAME.

--
Bubba
Jul 23 '05 #4
On Mon, 18 Oct 2004 04:08:40 GMT, Dag Sunde <ds@orion.no-way> wrote:
"Ryan" <rg******@comcast.netnospam> wrote in message
news:dc********************@comcast.com...
[snip]
<INPUT TYPE=\"hidden\" name=xmlfield >


[snip]
function ChangeFieldName (val) {
if( document.getElementById )
document.getElementById('xmlfield').value = val;
}


That won't help. The control is *named*; it does not have an id, which
makes getElementById patently useless. Furthermore, as there is a form (a
hidden value would be pointless, otherwise), using getElementById makes
the page unnecessarily backward-incompatible.

Mike

--
Michael Winter
Replace ".invalid" with ".uk" to reply by e-mail.
Jul 23 '05 #5
On Mon, 18 Oct 2004 00:22:06 -0400, Ryan <rg******@comcast.netnospam>
wrote:

Please don't top-post.
why do i need:

if( document.getElementById )
?


The getElementById method is a relatively recent addition to the Document
Object Model (DOM). Older browsers don't support it, so a technique known
as feature detection is used to check that a user agent supports the
method before a script tries to execute it.

More information can be found in the FAQ (<URL:http://jibbering.com/faq/>
- look for 4.26) and it's notes
(<URL:http://www.jibbering.com/faq/faq_notes/faq_notes.html>). You'll also
find information on how to reference form controls.

[snip]

Mike

--
Michael Winter
Replace ".invalid" with ".uk" to reply by e-mail.
Jul 23 '05 #6
"Bubba" <bu***@nospam.com> wrote in message news:<Ps********************@hebe.telenet-ops.be>...
Ryan wrote:
I have a hidden field as such:

<INPUT TYPE=\"hidden\" name=xmlfield >

I have a button that i want to use to call a function to change the
value:

<INPUT TYPE=submit VALUE="Display XML" Name="displayXML"
OnClick="ChangeFieldName('XML')">

here is the function

function ChangeFieldName (val) {
document.FieldName.xmlfield.value=val;};

nothing happens? The value is not set?


Use document.FORMNAME instead of document.FIELDNAME.

I tried the following and nothing worked.

document.formname.xmlfield.value = val
I also tried naming my form:

<FORM name=ADDRESSBOOK>

dont know if i need to name it when i do </FORM>

then did:

document.ADDRESSBOOK.xmlfield.value = val

this is what i am trying to do. I have a form. When a certain button
is pressed. I want to pass a value back to my java servlet. I thought
the best way to do it was to use a hidden field and set that with a
button. then i can retrieve it on the servlet side.
Jul 23 '05 #7
"Michael Winter" <M.******@blueyonder.co.invalid> wrote in message news:<opsf16n8uox13kvk@atlantis>...
On Mon, 18 Oct 2004 04:08:40 GMT, Dag Sunde <ds@orion.no-way> wrote:
"Ryan" <rg******@comcast.netnospam> wrote in message
news:dc********************@comcast.com...


[snip]
<INPUT TYPE=\"hidden\" name=xmlfield >


[snip]
function ChangeFieldName (val) {
if( document.getElementById )
document.getElementById('xmlfield').value = val;
}


That won't help. The control is *named*; it does not have an id, which
makes getElementById patently useless. Furthermore, as there is a form (a
hidden value would be pointless, otherwise), using getElementById makes
the page unnecessarily backward-incompatible.

Mike


i also tried the following which i got out of the gibbering faq.

document.forms["myform"].elements["xmlfield"].value=val
Jul 23 '05 #8
On 18 Oct 2004 10:21:20 -0700, Ryan Gaffuri <rg******@cox.net> wrote:

[snip]
I tried the following and nothing worked.

document.formname.xmlfield.value = val
I also tried naming my form:

<FORM name=ADDRESSBOOK>

dont know if i need to name it when i do </FORM>
No. Attributes only appear in the starting tag of an element.

Perhaps you should try validating your page
(<URL:http://validator.w3.org/>). Being unsure of something so basic
suggests you should revisit some HTML basics.
then did:

document.ADDRESSBOOK.xmlfield.value = val
Without actually seeing your page, it's diffcult to say what's wrong.
Nothing this simple should be so hard to solve. If you still need help in
this thread, please post your mark-up and the relevant script code.
Preferably this should be in the form of a simplified page, posted
somewhere on the Web. If that isn't possible, the same should be copied
and pasted in a post.
this is what i am trying to do. I have a form. When a certain button is
pressed. I want to pass a value back to my java servlet. I thought the
best way to do it was to use a hidden field and set that with a button.
then i can retrieve it on the servlet side.


From that description, and what you've posted, there's no need for
scripting at all.

Submit buttons, just like any other control, will submit a name/value pair
if the browser considers it a "successful control". There are two ways to
implement this: with a BUTTON element, or an INPUT element with type
"submit". The former will allow cleaner server-side processing, but it
won't work at all with NN4. The latter will work with all browsers, but it
will require changes to your server-side code.

<button type="submit" name="xmlfield"
value="XML">Display XML</button>

or

<input type="submit" name="xmlfield" value="Display XML">

You'll immediately notice that the two values to be submitted are
different. The problem with the INPUT element is that it's value is also
the text displayed.

Whichever of the two you'll choose, either will be a far better solution
than making your page reliant on script support.

Mike

--
Michael Winter
Replace ".invalid" with ".uk" to reply by e-mail.
Jul 23 '05 #9

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

Similar topics

1
by: George Rogic | last post by:
Hello: I've done an exhaustive online search and either can't find what I'm looking for or I'm unable to make what I've found work. I'm not a programmer, but I'm sure that this is probably...
1
by: Jim | last post by:
I have a 2 checkboxes and a hidden field..what I want to happen is that you can only click on 1 of these checkboxes at a time and when you check a checkbox it will assign the hidden field...
4
by: multimatum2 | last post by:
Hello, I need to enable/disable input text forms... But... I need to have the same style (color...) in both modes.. Could you help me ? Thanx a lot A small sample... ...
8
by: horos | last post by:
hey all, Ok, a related question to my previous one on data dumpers for postscript. In the process of putting a form together, I'm using a lot of placeholder variables that I really don't care...
6
by: iwearwatches | last post by:
Group, What a root canal. Here is what I have: I have a page that has several layers that I will either show/hide based on a graphic/tab that the user clicks. (works perfectly)
3
by: Jeremy Ames | last post by:
I have a form that contains two hidden values, among other controls. I was wondering, if I change these values in server script and immediately do a server.transfer, do these values get updated...
2
by: sheldonlg | last post by:
I have what is probably a very simple question, but I am VERY new to javascript. Here is what I want to accomplish. I have a text box called zp. I also have a hidden field called frm. There is...
1
by: peck2000 | last post by:
Related to my earleir post ... this is the same project to re-purpose the Classifieds application in BEGINNING ASP 3.0 (Wrox) to a comicbook database ... This is a brainteaser that should have...
1
by: mark | last post by:
Forgive me if this seems like a stupid question but I need help... I'm trying to do a simple online form that emails me the results from a few fields. Here is the code: <form...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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,...
0
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...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
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...
0
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...

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.