SitePoint Sponsor

User Tag List

Results 1 to 8 of 8

Hybrid View

  1. #1
    SitePoint Zealot kryptokid's Avatar
    Join Date
    Nov 2001
    Location
    Brisbane, Australia
    Posts
    108
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    changing visibility depending on dropdown box selection

    Hi Everyone,

    I want a text box which is only visible if the preceding drop down box has a certain option selected.

    Does anyone know how to do this or where I might be able to find the appropriate code?

    Thanks,

    Dan

  2. #2
    SitePoint Zealot kryptokid's Avatar
    Join Date
    Nov 2001
    Location
    Brisbane, Australia
    Posts
    108
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    ok this is what I've done so far, but it still doesn't work.

    I've placed a <div> with the id "audit" around the text box and set the style to visibility:hidden. Then on the drop down menu called "type", I've placed an onchange which performs the function called visible_no.

    The code for visble_no is:

    <i>function visible_no(){
    if (document.type.value = "audit issue") {
    div.audit.style = "visibility:visible";
    }
    else{
    div.audit.style = "visibility:hidden";
    }</i>

    If anyone can help, I'd greatly appreciate it.

    Thanks.

  3. #3
    SitePoint Zealot kryptokid's Avatar
    Join Date
    Nov 2001
    Location
    Brisbane, Australia
    Posts
    108
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    forget the <i>'s I thought it would display my code in italics

  4. #4
    SitePoint Member Toxical's Avatar
    Join Date
    Apr 2002
    Posts
    20
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Code:
    function visible_no(what){
    
    if (what.value = "audit issue") {
    
    div.audit.style.visibility = "visible";
    
    }
    
    else{
    
    div.audit.style.visibility = "hidden";
    
    }
    I think you've got an onchange handler in your select tag haven't you?

    Code:
    <form name="form1" action="" enctype="">
    
    <select name="type" onchange="javascript:visible_no(this);">
    
    <!--...//-->
    
    </select>
    
    </form>
    Go here to read about how to post code 'userfriendy'
    I beg your pardon for my bad English

  5. #5
    SitePoint Zealot kryptokid's Avatar
    Join Date
    Nov 2001
    Location
    Brisbane, Australia
    Posts
    108
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Yep, I had an onchange in the select tag.

    It's now telling me that "div is not defined" (referring to
    PHP Code:
    div.audit.style.visibility "visible"
    in the function.)

    This is how I've got the <div> in the body code.

    PHP Code:
    <div id="audit" style="visibility:hidden">Audit No. :&nbsp;&nbsp;<input type="text" name="textfield"></div

  6. #6
    SitePoint Zealot kryptokid's Avatar
    Join Date
    Nov 2001
    Location
    Brisbane, Australia
    Posts
    108
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    By the way, that's Netscape giving me that error. IE works fine.

    I don't think it's necessary for it to work in Netscape because the only people that will need to fill in that visible/invisible field are people who work within the company and IE is the only browser in use.

    So thanks for your help, Toxical.

  7. #7
    SitePoint Member Toxical's Avatar
    Join Date
    Apr 2002
    Posts
    20
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Oh yes, havn't thought 'bout that div so far
    try
    PHP Code:
    document.audit.style.visibility "visible";
    //or
    document.all.audit.style.visibility "visible";
    //or
    document.getElementById("audit").style.visibility "visible"
    I think, one of these possibilities should work in netscape as well.
    I beg your pardon for my bad English

  8. #8
    SitePoint Zealot kryptokid's Avatar
    Join Date
    Nov 2001
    Location
    Brisbane, Australia
    Posts
    108
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Originally posted by Toxical

    PHP Code:
    document.getElementById("audit").style.visibility "visible"
    I think, one of these possibilities should work in netscape as well.
    Toxical,

    This was the one that worked. Thanks again for your help.

    Dan


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
  •