SitePoint Sponsor

User Tag List

Results 1 to 11 of 11
  1. #1
    SitePoint Zealot -rob-'s Avatar
    Join Date
    Mar 2003
    Location
    Earth
    Posts
    119
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Question Retrieving post value of checkbox

    Hi,

    I have a checkbox that I do not want the user to be able to change the value of. I post the form, and then I have to retrieve this value on the following page.

    Does anyone know how to do this?

    "disable"ing the element stops the value from being posted.

    Thanks in advance.
    Cheers,

    -rob-

  2. #2
    Free your mind Toly's Avatar
    Join Date
    Sep 2001
    Location
    Panama
    Posts
    2,181
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Something like this perhaps?
    HTML Code:
    <input type="checkbox" name="check" disabled value="" checked>
    Edit:


    "disable"ing the element stops the value from being posted.
    I have an input field disabled with a value on my website and I'm able to pass it without any problems.
    Community Guidelines | Community FAQ

    "He that is kind is free, though he is a slave;
    he that is evil is a slave, though he be a king." - St. Augustine

  3. #3
    SitePoint Zealot -rob-'s Avatar
    Join Date
    Mar 2003
    Location
    Earth
    Posts
    119
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Not quite, by disabling the element, the value is not posted, so you can not retrieve the value in the following page.

    At the moment I have added this onClick event to the submit button:
    Code:
     onclick="document.form.checkbox1.disabled=false;document.form.checkbox2.disabled=false;"
    but I am hoping there is a better method.
    Cheers,

    -rob-

  4. #4
    ☆★☆★ silver trophy vgarcia's Avatar
    Join Date
    Jan 2002
    Location
    in transition
    Posts
    21,235
    Mentioned
    1 Post(s)
    Tagged
    1 Thread(s)
    Use the readonly attribute if you want the value of the checkbox to post, but not to be edited:
    HTML Code:
    <input type="checkbox" name="cb1" value="yes" readonly="readonly" />

  5. #5
    SitePoint Zealot -rob-'s Avatar
    Join Date
    Mar 2003
    Location
    Earth
    Posts
    119
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    The readonly attribute does not stop the user from checking and unchecking a Checkbox, even though the value does not change.
    Last edited by -rob-; Oct 22, 2003 at 10:03.
    Cheers,

    -rob-

  6. #6
    Free your mind Toly's Avatar
    Join Date
    Sep 2001
    Location
    Panama
    Posts
    2,181
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by -rob-
    Not quite, by disabling the element, the value is not posted, so you can not retrieve the value in the following page.
    This is the only method I know off. As I already said, I use this method on my website and the variable passes just fine from a disabled field.
    Community Guidelines | Community FAQ

    "He that is kind is free, though he is a slave;
    he that is evil is a slave, though he be a king." - St. Augustine

  7. #7
    SitePoint Zealot -rob-'s Avatar
    Join Date
    Mar 2003
    Location
    Earth
    Posts
    119
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Toly,

    Are you POST'ing or GET'ing the data?

    Please read the information at http://www.faqs.org/docs/htmltut/for..._DISABLED.html and let me know what browser you are using.

    Thank you.
    Cheers,

    -rob-

  8. #8
    Free your mind Toly's Avatar
    Join Date
    Sep 2001
    Location
    Panama
    Posts
    2,181
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Well, according to that link, the disabled field is not sent when the form is submitted but I'm not sure how old that information is. They state that only IE recognizes the disabled attribute and that is not true.

    My disabled field gets submitted just fine with IE 6.0, NS 7+ and Firebird. All through POST.
    Community Guidelines | Community FAQ

    "He that is kind is free, though he is a slave;
    he that is evil is a slave, though he be a king." - St. Augustine

  9. #9
    SitePoint Zealot -rob-'s Avatar
    Join Date
    Mar 2003
    Location
    Earth
    Posts
    119
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    According to the HTML 4.01 docs (http://www.w3.org/TR/REC-html40/inte...html#h-17.12.1) a disabled element should not be successful so I do not know why yours are working, but then we are talking web browsers here.
    Cheers,

    -rob-

  10. #10
    The doctor is in... silver trophy MarcusJT's Avatar
    Join Date
    Jan 2002
    Location
    London
    Posts
    3,509
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    >>Nods<<
    MarcusJT
    - former ASP web developer / former SPF "ASP Guru"
    - *very* old blog with some useful ASP code

    - Please think, Google, and search these forums before posting!

  11. #11
    SitePoint Zealot sam0010's Avatar
    Join Date
    Aug 2003
    Posts
    101
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You can always make images of a check box that is check and an image of one that isnt. Pass the values in a hidden input and show the corosponding checkbox image.
    # SAMO #

    Great sites coming soon!!


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •