www.webdeveloper.com
Results 1 to 9 of 9

Thread: selectbox show input filed

  1. #1
    Join Date
    Oct 2010
    Posts
    14

    selectbox show input filed

    Hello,

    I have this code:
    PHP Code:
    <script
        function 
    checkForOther(obj
        { 
            if (!
    document.layers
            { 
                var 
    txt document.getElementById("otherTitle"); 
                if (
    obj.value == "new"
                { 
                    
    txt.style.display "inline"
                    
    // gives the text field the name of the drop-down, for easy processing 
                    
    txt.name "selTitle"
                    
    obj.name ""
                } 
                else 
                { 
                    
    txt.style.display "none"
                    
    txt.name ""
                    
    obj.name "selTitle"
                } 
            } 
        } 
    </script> 
    it's should hide/show input field accourding the user choice - if he choose "<option value='new'>new</option>", the follow action should happend:

    PHP Code:
                    <li id='otherTitle'>
                        <
    label for='new'>new artist</label>
                        <
    input type='text'  name='new_artist_name' />                
                    </
    li
    The script works, but when I click "submit" the parameter that the "select box" should send don't get send...

    here is the full code:
    PHP Code:
                    <li>
                        <
    label for='artist'>Artists</label>
                        <
    select name='artist_id' onchange=\"checkForOther(this)\">
                            <option value='new'>new artist</option>"
    ;
                            
    $query mysql_query("SELECT id, name FROM `chords_artists` ORDER BY `name` ");
                            while(
    $index mysql_fetch_array($query)) 
                            {    
                                
    $artist_id $index['id'];
                                
    $artist $index['name'];
                                echo 
    "<option value='$artist_id'>$artist</option>";
                            }
                            
                        echo 
    "    
                        </select>
                    </li>    
                    
                    <li id='otherTitle'>
                        <label for='new'>new artist:</label>
                        <input type='text'  name='new_artist_name' />                
                    </li> 
    Can you please help me with it?

  2. #2
    Join Date
    Apr 2003
    Location
    Netherlands
    Posts
    21,654
    No name, then no value can be sent. Why remove the name of the select?

    document.layers is obsolete, don't use it.
    At least 98% of internet users' DNA is identical to that of chimpanzees

  3. #3
    Join Date
    Oct 2010
    Posts
    14
    Hi Fang
    I'm not familier with JS code, but in the form code I see that there is name, here:
    <select name='artist_id' onchange="checkForOther(this)\">

  4. #4
    Join Date
    Apr 2003
    Location
    Netherlands
    Posts
    21,654
    and removed here
    Code:
    obj.name = "";
    At least 98% of internet users' DNA is identical to that of chimpanzees

  5. #5
    Join Date
    Oct 2010
    Posts
    14
    Emm, still not working

  6. #6
    Join Date
    Apr 2003
    Location
    Netherlands
    Posts
    21,654
    Remove that statement and the select name/value pair will be submitted.
    At least 98% of internet users' DNA is identical to that of chimpanzees

  7. #7
    Join Date
    Oct 2010
    Posts
    14
    Because my lack knowledge in JS i don't know which code you ment.
    can you please copy to your post the part that I need to remove?

  8. #8
    Join Date
    Apr 2003
    Location
    Netherlands
    Posts
    21,654
    Code:
    <script type="text/javascript">
        function checkForOther(obj)
        {
                var txt = document.getElementById("otherTitle");
                if (obj.value == "new")
                {
                    txt.style.display = "inline";
                }
                else
                {
                    txt.style.display = "none";
                }
        }
    </script>
    The script would have worked if the id 'otherTitle' was a reference to the input rather than the list element, although the server-script would not work correctly if JavaScript was disabled.
    At least 98% of internet users' DNA is identical to that of chimpanzees

  9. #9
    Join Date
    Oct 2010
    Posts
    14
    so simple, ha...
    Thanks!

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

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



Recent Articles