Results 1 to 10 of 10

Thread: check readonly

  1. #1
    Join Date
    Jun 2007
    Posts
    64
    Thanks
    6
    Thanked 0 Times in 0 Posts

    Arrow check readonly

    Hi !

    Is it possible to check if a form input is readonly or not ?
    for example i have a form input like this:

    <input id="name" type="text" name="name" value="Name" readonly="readonly">

    can i check via javascript, onclick, if the input field is readonly or not ?

    thx for help

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

    Default

    Code:
    if(document.getElementById("name").readonly) {
      /* . . . */
    }
    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!

  3. #3
    Join Date
    Jun 2007
    Posts
    64
    Thanks
    6
    Thanked 0 Times in 0 Posts

    Default hey!

    thx for ya fast replie ! works nice...
    another small question..

    now inside "/* . . . */" .. is it possible to change a value that has been entered in the form input ?
    For example if someone puts a name like "John" and now inside the function i want to add a prefix like "guest:" ..

    manipulating the value after someone allready clicked the submit button button.. ?

    thx again !

  4. #4
    Join Date
    Jun 2006
    Posts
    182
    Thanks
    0
    Thanked 14 Times in 14 Posts

    Default

    Code:
    var txtBox = document.getElementById("name");
    txtBox.value = "Guest: " + txtBox.value

  5. #5
    Join Date
    Jun 2007
    Posts
    64
    Thanks
    6
    Thanked 0 Times in 0 Posts

    Default :)

    hey ! thx alot, it works great !!

    one more thing...
    this line:

    PHP Code:
    if(document.getElementById("name").readonly
    how can i do it the negative way.. i tried

    PHP Code:
    if(!document.getElementById("name").readonly
    but i did not work..


    thx again

  6. #6
    Join Date
    Jun 2007
    Posts
    64
    Thanks
    6
    Thanked 0 Times in 0 Posts

    Exclamation

    ok here is more code...

    This is the input part inside the form ->
    PHP Code:
    if ($nickname == 'Anonymous') {
    $name "<input id=\"sbCookie\" maxlength=\"22\" class=\"inputWidth\" onFocus=\"clearField(this);\" value=\"Anonymous\" onBlur=\"checkField(this);\" type=\"text\" name=\"".$field."0\">\n\r";    
    } else {
    $name "<input id=\"sbCookie\" maxlength=\"15\" class=\"inputWidth\" onFocus=\"clearField(this);\" value=\"".$SBTEXT['field_name']."\" onBlur=\"checkField(this);\" type=\"text\" name=\"".$field."0\" readonly=\"readonly\">\n\r";    

    and this is the javascript part which checks the input ->
    Code:
    if(form.elements[val+'0'].readonly) {
    var nameBox = form.elements[val+'0'];
    } else {
    var nameBox = form.elements[val+'0'];
    nameBox.value = "Guest: " + nameBox.value
    }
    the problem is, that i get the "Guest" Prefix every time..
    no matter what.. plz help !!

    thx

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

    Default

    Quote Originally Posted by kobo1d View Post
    Code:
    if(document.getElementById("name").readonly)
    If the control in question is part of a form, don't use the getElementById method. Use the forms and elements collections, instead - there's no need for the control to even have an id attribute except for the purposes of CSS or related label elements.

    how can i do it the negative way.. i tried

    Code:
    if(!document.getElementById("name").readonly)
    The property name is readOnly; note the capital O, which is very significant.

    Hope that helps
    Mike

  8. #8
    Join Date
    Jun 2007
    Posts
    64
    Thanks
    6
    Thanked 0 Times in 0 Posts

    Thumbs up

    The property name is readOnly; note the capital O, which is very significant.

    Hope that helps
    ineed that helped lol !! that was the problem..
    i made the o to an O and everything worked.. amazing

    thx alot!

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

    Default

    My error, sorry!
    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!

  10. #10
    Join Date
    Jan 2008
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default DimX

    Thanks for the menu I really like it, but I am experiencing a little problem.
    When I add a rollover image to the page the menu stops respondig. Have you seen this problem before? is there a way around it? Do one script intervines with the other, because once I delete what I have added the menu works fine again. This happens in both browsers FireFox and IE.

    also, I tried to comment or remove the remember part of the script so the page wont write a cookie but I get the same results, the menu stops responding. Can you help me Dimx, thanks again.

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
  •