<input type="image" ... does not show up as a form element! why?

Discussion in 'Javascript' started by Dave, Apr 10, 2004.

  1. Dave

    Dave Guest

    Hi all,

    I was trying to make an image submit button with a rollover and discovered
    to my suprise that there is no way to access a form element of the "image"
    type. I tried specifying it by name and also by the elements[] array with
    no luck.
    Even weirder, I can sandwich an image button in between other input types
    and then write a script diplaying the contents of the elements array and it
    acts as if the image button does not exist at all!
    For example the following:
    <input type="text" ... > : this is elements[0]
    <input type="checkbox" ...> : this is elements[1]
    <input type="image" ...> : this does not exist!
    <input type="text" ...> : this is elements[2]

    Does anyone know of any way to access (or set) the properties of an image
    input type?
    I ask, because I wanted to have a rollover action on a button that also can
    POST a form WITHOUT using submit() - in order that non-Javascript enabled
    browsers can fail gracefully (i.e. the form is still POSTed).


    TIA!
    MC Dave
    Dave, Apr 10, 2004
    #1
    1. Advertising

  2. Dave

    Dave Guest

    Solution:
    Because the "image button" is not accessible via the elements collection nor
    by directly naming it (i.e. forms[0].elements[5] OR myform.BTNcontinue)
    BUT you can utilize "this" to change a property directly as in the example
    below where a rollover can be specified directly:

    <INPUT TYPE="image" name="BTNcontinue"
    src="images/buttons/btncontinueshopping.gif"
    onmouseover="this.src='images/buttons/btncontinueshopping_f2.gif'"
    onmouseout="this.src='images/buttons/btncontinueshopping.gif'">

    To reference it from an outside script:
    <INPUT TYPE="image" name="BTNcontinue"
    src="images/buttons/btncontinueshopping.gif" onmouseover="rollon(this);"
    onmouseout="rolloff(this);">

    <script language="JavaScript">

    function rollon(myref)
    {
    myref.src='images/buttons/btncontinueshopping_f2.gif';
    }

    function rolloff(myref)
    {
    myref.src='images/buttons/btncontinueshopping.gif';
    }

    </script>



    "Dave" <dave(delete_this)@miraclecatDELETETHISTOO.com> wrote in message
    news:V_Xdc.4287$xn4.17460@attbi_s51...
    > Hi all,
    >
    > I was trying to make an image submit button with a rollover and discovered
    > to my suprise that there is no way to access a form element of the "image"
    > type. I tried specifying it by name and also by the elements[] array with
    > no luck.
    > Even weirder, I can sandwich an image button in between other input types
    > and then write a script diplaying the contents of the elements array and

    it
    > acts as if the image button does not exist at all!
    > For example the following:
    > <input type="text" ... > : this is elements[0]
    > <input type="checkbox" ...> : this is elements[1]
    > <input type="image" ...> : this does not exist!
    > <input type="text" ...> : this is elements[2]
    >
    > Does anyone know of any way to access (or set) the properties of an image
    > input type?
    > I ask, because I wanted to have a rollover action on a button that also

    can
    > POST a form WITHOUT using submit() - in order that non-Javascript enabled
    > browsers can fail gracefully (i.e. the form is still POSTed).
    >
    >
    > TIA!
    > MC Dave
    >
    >
    Dave, Apr 10, 2004
    #2
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Guy
    Replies:
    5
    Views:
    2,812
    brucie
    Dec 13, 2003
  2. Mr. SweatyFinger
    Replies:
    2
    Views:
    1,761
    Smokey Grindel
    Dec 2, 2006
  3. Replies:
    18
    Views:
    24,759
    tallnhairy
    Sep 28, 2011
  4. greenflame
    Replies:
    6
    Views:
    142
    greenflame
    Jun 18, 2005
  5. Randell D.
    Replies:
    12
    Views:
    244
    Randell D.
    Jul 6, 2005
Loading...

Share This Page