Hello and thanks for taking the time to review my request for help
I am creating a timesheet entry program and am having trouble with one part of it since I am not very good with javascript.
I have a dropdown box containing certain types of entries that are available and want to make it so that when certain choices in the dropdown are selected, certain things happen like the description box is populated with certain text, and when travel time is picked I want it to make a couple divs visible.
My non-working javascript
:
Code:
<script type="text/javascript">
function type_select() {
val = document.Form.type_id.options[document.Form.type_id.selectedIndex].value;
textbox = document.Form.description;
if (val = '0')
{
textbox.value = "0- Nothing selected";
document.getElementById('div1').style.display = "block";
document.getElementById('div2').style.display = "block";
}
if (val = '1')
{
textbox.value = "1- Ticket #:";
document.getElementById('div1').style.display = "none";
document.getElementById('div2').style.display = "none";
}
if (val = '2' )
{
textbox.value = "2- From: To:";
document.getElementById('div1').style.display = "block";
document.getElementById('div2').style.display = "block";
}
if (val = '3' )
{
textbox.value = "3- ";
document.getElementById('div1').style.display = "none";
document.getElementById('div2').style.display = "none";
}
if (val = '4' )
{
textbox.value = "4- ";
document.getElementById('div1').style.display = "none";
document.getElementById('div2').style.display = "none";
}
if (val = '5' )
{
textbox.value = "5- Holiday:";
document.getElementById('div1').style.display = "none";
document.getElementById('div2').style.display = "none";
}
if (val = '6' )
{
textbox.value = "6- Illness:";
document.getElementById('div1').style.display = "none";
document.getElementById('div2').style.display = "none";
}
if (val = '7' )
{
textbox.value = "7- ";
document.getElementById('div1').style.display = "none";
document.getElementById('div2').style.display = "none";
}
if (val = '8' )
{
textbox.value = "8- ";
document.getElementById('div1').style.display = "none";
document.getElementById('div2').style.display = "none";
}
}
</script>
This is the HTML for the dropdown, and textarea
Code:
<td align=center>
<SELECT NAME="type_id" class="menumain" OnChange="type_select();">
<option value="0">Choose One</option>
<OPTION VALUE="1" >ticket</option>
<OPTION VALUE="2" >travel</option>
<OPTION VALUE="3" >personal</option>
<OPTION VALUE="4" >planning</option>
<OPTION VALUE="5" >holiday</option>
<OPTION VALUE="6" >vacation</option>
<OPTION VALUE="7" >sick</option>
<OPTION VALUE="8" >training</option>
</select>
</td>
<td align=center>
<TEXTAREA class="menumain" cols=20 name="description" rows=4 wrap=virtual title="Enter The Note Description In This Box. Please Be As Specific As Possible"></TEXTAREA>
</td>
<td align=center>
<div id="div1" style="display:none;">
<input type=text value="" class=menumain size=20 name="odom_start" title="Beginning Odometer Value" >
</div>
</td>
<td align=center>
<div id="div2" style="display:none;">
<input type=text value="" class=menumain size=20 name="odom_end" title="Ending Odometer Value" >
</div>
</td>
So far what happens is that no matter what I choose in the drop down it will always populate it as if I selected the last choice.
Do I need to make it return once it found the right choice or somethng and if so then how do I do that?