changing the value of a hidden field

Discussion in 'Javascript' started by Ryan, Oct 18, 2004.

  1. Ryan

    Ryan Guest

    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"

    here is the function

    function ChangeFieldName (val) {

    nothing happens? The value is not set?
    Ryan, Oct 18, 2004
    1. Advertisements

  2. Ryan

    Dag Sunde Guest

    function ChangeFieldName (val) {
    if( document.getElementById )
    document.getElementById('xmlfield').value = val;
    Dag Sunde, Oct 18, 2004
    1. Advertisements

  3. Ryan

    Ryan Guest

    why do i need:

    if( document.getElementById )
    Ryan, Oct 18, 2004
  4. Ryan

    Bubba Guest

    Use document.FORMNAME instead of document.FIELDNAME.
    Bubba, Oct 18, 2004
  5. 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.

    Michael Winter, Oct 18, 2004
  6. Please don't top-post.
    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:>
    - look for 4.26) and it's notes
    (<URL:>). You'll also
    find information on how to reference form controls.


    Michael Winter, Oct 18, 2004
  7. Ryan

    Ryan Gaffuri Guest

    I tried the following and nothing worked.

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


    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.
    Ryan Gaffuri, Oct 18, 2004
  8. Ryan

    Ryan Gaffuri Guest

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

    Ryan Gaffuri, Oct 18, 2004
  9. [snip]
    No. Attributes only appear in the starting tag of an element.

    Perhaps you should try validating your page
    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.
    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>


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

    Michael Winter, Oct 18, 2004
    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.