Web Analytics Made Easy -
StatCounter Setting a hidden value in a form from an onClick event... - CodingForum

Announcement

Collapse
No announcement yet.

Setting a hidden value in a form from an onClick event...

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Setting a hidden value in a form from an onClick event...

    Hey folks. This might be a basic question but I'm having trouble with this one...

    I have a form...
    ==========================================
    <form name="songRatingForm" method="post" action="">
    <input name="songID" type="hidden" id="songID" value="5357">
    <input name="formSent" type="hidden" id="formSent" value="y">
    <input name="Submit" type="submit" value="Rate It!">
    </form>

    and I have 3 images.
    ====================================
    [img1] [img2] [img3]


    When [img1] is clicked I want the following value to be set..
    <input name="rating" type="hidden" id="rating" value="1">

    When [img2] is clicked I want the following value to be set..
    <input name="rating" type="hidden" id="rating" value="2">

    When [img3] is clicked I want the following value to be set..
    <input name="rating" type="hidden" id="rating" value="3">


    How is this achieved using the onClick method? (I'll be using the mouseOver in conjunction with this too)


    Thanks for all your help!
    Last edited by erdubya; Oct 3, 2006, 01:30 PM. Reason: better readibility
    Elliott
    http://projectvibe.net

  • #2
    How are the images labeled? It would probably easier to just assign a radio button to the image.
    Code:
    <form name="songRatingForm" method="post" action="">
    <input name="songID" type="hidden" id="songID" value="5357">
    <input name="formSent" type="hidden" id="formSent" value="y">
    <input name="rating" type="radio" id="rating" value="1"><img src="img1.jpg" alt=""><br>
    <input name="rating" type="radio" value="2"><img src="img2.jpg" alt=""><br>
    <input name="rating" type="radio" value="3"><img src="img3.jpg" alt=""><br>
    <input name="Submit" type="submit" value="Rate It!">
    </form>
    This way no JS is required.
    ||||If you are getting paid to do a job, don't ask for help on it!||||

    Comment


    • #3
      Hey Thanks _Aerospace_Eng_.

      I wanted to incorporate a hover (mouseOVer) to achieve the following...
      =====================================================
      you have
      [img1] [img2] [img3]
      lined up horizontally...

      When the user hovers over imgage 1, [img1] lights up (i.e. swap image via mouseOver)
      A click on this image sets the "rating" variable to 1.


      When the user hovers over imgage 2, [img1] and [img2] light up (i.e. swap image via mouseOver)
      A click on this image sets the "rating" variable to 2.


      When the user hovers over imgage 3, [img1], [img2] and [img3] light up (i.e. swap image via mouseOver)
      A click on this image sets the "rating" variable to 3.


      After the user clicks on the number they'll then click the submit button to send the info.

      Can mouseOver as described above still be incorporated with the form you gave?

      Elliott
      Elliott
      http://projectvibe.net

      Comment


      • #4
        Yeah just put onmouseover on the image. I see no need for you to set a hidden value using onclick. The radio buttons will send the correct value to your form processor.
        ||||If you are getting paid to do a job, don't ask for help on it!||||

        Comment

        Working...
        X