Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 6 of 6
  1. #1
    Regular Coder che_anj's Avatar
    Join Date
    Aug 2006
    Location
    Philippines
    Posts
    157
    Thanks
    12
    Thanked 3 Times in 3 Posts

    problems with onchange

    Hello anybody has an idea on how to display textbox when selecting item in the select box.

    heres my code...

    PHP Code:
    <script type="text/javascript">

    function 
    displaytext()
    {
    var 
    actiontype document.forms['actions']['eventcat'];
    var 
    schedule document.forms['actions']['date3'];

    if (
    actiontype.options[actiontype.selectedIndex].value == "1"
    {
    schedule.style.display 'inline';

    else if (
    actiontype.options[actiontype.selectedIndex].value == "2"
    {
    schedule.style.display 'inline';
    }
    else 
    {
    schedule.style.display 'none';
    }
    }

    </script> 
    PHP Code:
    <?php
    echo '<form name="actions">
    <tr><td>Action Type</td>
    <td>'
    .html_select("eventcat",0,array_of("eventcat"),"",$actype).'</td>
    </tr>
    <tr><td>Interview Schedule</td>
    <td>
    <input type="text" name="date3" id="sel3" size="20" readonly value="'
    .$rowa[edate].'"><input type="reset" value=" ... "
    onclick="return showCalendar(\'sel3\', \'%Y-%m-%d\');">
    </td>
    </tr>
    </form>'
    ;
    ?>
    When I click an item in the select box the Interview Schedule row will display.. tnx..

  • #2
    New Coder
    Join Date
    Aug 2007
    Posts
    26
    Thanks
    0
    Thanked 4 Times in 4 Posts
    PHP Code:
    $types = array ('Default''Type 1''Type 2');
    echo 
    "<form method='post'>";
    echo 
    "<select size='1' name='my_choice' onChange='this.form.submit();'>";
    foreach (
    $types as $k => $v) {
        
    $sel = ($k == $_POST['my_choice']) ? ' selected ' ''
        echo 
    "<option $sel value='$k'>$v</option>";
    }    
    echo 
    "</select>";
    if (
    $_POST['my_choice'] == 2) {
        echo 
    " Type 2 : <input type='text' name='data2'>";
    } else if (
    $_POST['my_choice'] == 1) {
        echo 
    " Type 1 : <input type='text' name='data1'>";
    } else {    
        echo 
    " Default : <input type='text' name='data2'>";
    }    
    echo 
    "</form>"

  • #3
    Regular Coder che_anj's Avatar
    Join Date
    Aug 2006
    Location
    Philippines
    Posts
    157
    Thanks
    12
    Thanked 3 Times in 3 Posts
    Ive got this example..

    <script type="text/javascript">

    function toggleField(val) {
    var o = document.getElementById('datetext');
    var c = document.getElementById('dbutton');
    (val == '1' || val=='2')? o.style.display = 'block' : o.style.display = 'none';
    (val == '1' || val=='2')? c.style.display = 'block' : c.style.display = 'none';
    }


    </script>

    <form action="" method="post">
    '.html_select("eventcat",0,array_of("eventcat"),"",$actype,"toggleField(this.value);").'
    <input type="text" name="datetext" id="datetext" style="display: none;">
    <input type="reset" name="dbutton" id="dbutton" style="display: none;">
    </form>

    my question is how can i combine the "datetext" and "dbutton" in variable.

    tnx

  • #4
    Regular Coder che_anj's Avatar
    Join Date
    Aug 2006
    Location
    Philippines
    Posts
    157
    Thanks
    12
    Thanked 3 Times in 3 Posts
    well, ive tried your php version of onchange, but the problem is when it loads the values of my other textboxes will disappear and also the item that I clicked on the select box will back to the default..

    heres what i did..

    $types = array ('1', '2', '3','8');
    echo "<form method='post'>";
    echo ''.html_select("eventcat",0,array_of("eventcat"),"",$actype,"this.form.submit();").'';
    if (($_POST['eventcat'] == 1) || ($_POST['eventcat'] == 2) || ($_POST['eventcat'] == 8))
    {
    echo " Interview Schedule : <input type='text' name='data2'>";
    }

    echo "</form>";

  • #5
    New Coder
    Join Date
    Aug 2007
    Posts
    26
    Thanks
    0
    Thanked 4 Times in 4 Posts
    solved?

  • #6
    Regular Coder che_anj's Avatar
    Join Date
    Aug 2006
    Location
    Philippines
    Posts
    157
    Thanks
    12
    Thanked 3 Times in 3 Posts
    Yeah Ive solved it already.. your absent yesterday...

    Anyway.. Thanks a lot...


  •  

    Posting Permissions

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