...

View Full Version : problems with onchange



che_anj
08-29-2007, 04:42 PM
Hello anybody has an idea on how to display textbox when selecting item in the select box.

heres my 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
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..

Bahamut
08-29-2007, 05:06 PM
$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>";

che_anj
08-30-2007, 08:52 AM
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

che_anj
08-30-2007, 10:49 AM
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>";

Bahamut
08-31-2007, 12:50 PM
solved?

che_anj
08-31-2007, 01:14 PM
Yeah Ive solved it already.. your absent yesterday...

Anyway.. Thanks a lot...



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum