Page 1 of 2 12 LastLast
Results 1 to 10 of 12

Thread: A javascript problem, help me!!!

  1. #1
    Join Date
    May 2006
    Posts
    13
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default A javascript problem, help me!!!

    Today, I meet a problem.

    A checkbox and a text in a page, if I want the text is disabled unless the checkbox is checked, how can I write that javascript?

    Anyone who can help me?

  2. #2
    Join Date
    Mar 2005
    Location
    SE PA USA
    Posts
    30,495
    Thanks
    82
    Thanked 3,449 Times in 3,410 Posts
    Blog Entries
    12

    Default

    Code:
    <form action="">
    <input type="text" name="tr" disabled="1"><input type="checkbox" onclick="if (this.checked){this.form.tr.disabled=0}else{this.form.tr.disabled=1}">
    </form>
    - John
    ________________________

    Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate

  3. #3
    Join Date
    May 2006
    Posts
    13
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Aha!, that works.

    Thank you, jscheuer1 !!!

  4. #4
    Join Date
    Jun 2005
    Location
    英国
    Posts
    11,876
    Thanks
    1
    Thanked 180 Times in 172 Posts
    Blog Entries
    2

    Default

    Quote Originally Posted by John
    <form action="">
    method is required.
    Twey | I understand English | 日本語が分かります | mi jimpe fi le jbobau | mi esperanton komprenas | je comprends français | entiendo español | tôi ít hiểu tiếng Việt | ich verstehe ein bisschen Deutsch | beware XHTML | common coding mistakes | tutorials | various stuff | argh PHP!

  5. #5
    Join Date
    Dec 2004
    Location
    UK
    Posts
    2,358
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Quote Originally Posted by Twey
    Quote Originally Posted by John
    <form action="">
    method is required.
    No, it isn't. It defaults to the GET request method. Only the action attribute is required, though an empty value might not be a good idea: IE resolves empty href attributes incorrectly, so it's feasible that others will have similar issues not restricted to that particular attribute.

    Mike

  6. #6
    Join Date
    Jun 2005
    Location
    英国
    Posts
    11,876
    Thanks
    1
    Thanked 180 Times in 172 Posts
    Blog Entries
    2

    Default

    Oh, so it isn't. My apologies -- could have sworn I'd had trouble validating that before.
    Twey | I understand English | 日本語が分かります | mi jimpe fi le jbobau | mi esperanton komprenas | je comprends français | entiendo español | tôi ít hiểu tiếng Việt | ich verstehe ein bisschen Deutsch | beware XHTML | common coding mistakes | tutorials | various stuff | argh PHP!

  7. #7
    Join Date
    Mar 2005
    Location
    SE PA USA
    Posts
    30,495
    Thanks
    82
    Thanked 3,449 Times in 3,410 Posts
    Blog Entries
    12

    Default

    Thanks, Mike. I was out to sea on this one. Only reason I included it at all was that it is in my editors' 'come with' form boiler plate. But, as previously noted in these forums, others may use the value of their choice. I suppose if no action is truly desired:

    Code:
    action="javascript:void(0);"
    would do. I have never seen this cause a problem though, leaving it blank, but I suppose anything is possible, as you note.
    - John
    ________________________

    Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate

  8. #8
    Join Date
    Jun 2005
    Location
    英国
    Posts
    11,876
    Thanks
    1
    Thanked 180 Times in 172 Posts
    Blog Entries
    2

    Default

    If that works, it will cause nothing to happen when the form is submitted. This is different to the effect of an empty action or "?", which will cause the form to be submitted to the current page.
    Twey | I understand English | 日本語が分かります | mi jimpe fi le jbobau | mi esperanton komprenas | je comprends français | entiendo español | tôi ít hiểu tiếng Việt | ich verstehe ein bisschen Deutsch | beware XHTML | common coding mistakes | tutorials | various stuff | argh PHP!

  9. #9
    Join Date
    Mar 2005
    Location
    SE PA USA
    Posts
    30,495
    Thanks
    82
    Thanked 3,449 Times in 3,410 Posts
    Blog Entries
    12

    Default

    Well, we're talking here about a form that never gets submitted. I would think that if a user were to adapt the code to a form that does get submitted, they would have to set the values that impact submission behavior appropriately to their objectives. Submission or lack thereof has no impact on the functionality of my solution to the original question. All this is really beyond the scope of the question posed and answered originally. I think I will give Twey a nitpicking award for this one and Mike a clarification of a nit pick award though, he was mostly just responding to an obvious (to him) error on Twey's part.
    Last edited by jscheuer1; 05-10-2006 at 07:43 PM.
    - John
    ________________________

    Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate

  10. #10
    Join Date
    Jun 2005
    Location
    英国
    Posts
    11,876
    Thanks
    1
    Thanked 180 Times in 172 Posts
    Blog Entries
    2

    Default

    Heh... (wears "pedant of the year" award with pride)
    Twey | I understand English | 日本語が分かります | mi jimpe fi le jbobau | mi esperanton komprenas | je comprends français | entiendo español | tôi ít hiểu tiếng Việt | ich verstehe ein bisschen Deutsch | beware XHTML | common coding mistakes | tutorials | various stuff | argh PHP!

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
  •