开发者

how can i call different function by change dropdown menu option

this is my code

<html>
<head>
<body>
<form  name="form2">
<table>
<tr>
<td>
<b>From Date</b>:</td><td><input type="text" id="from_date" readonly="true" name="f_date"><a href="javascript: show_cal('document.form2.f_date.value')"><img src="images/cal.gif" width="16" height="16" border="0" alt="Pick a date"></a></td>
<td><b>To Date:</td><td></b><input type="text" id="to_date" readonly="true" name="t_date"><a href="javascript: show_cal('document.form2.t_date.value')"><开发者_JAVA百科img src="images/cal.gif" width="16" height="16" border="0" alt="Pick a date"></a></td>
<td><b>Vehicle Number</b>:</td><td><input type="text" id="vhc_number">
<td><input type="button" value="show report" onclick="show_record_monthly()" style="background-color:#E6E6DC"></td>
<td>
<select name="aa" onchange="report(this.value)"> 
<option value="">Please select</option>
<option value="da">daily</option>
<option value="mo">monthly</option>
<select>

**

i want to do it that when i select option from dropdownmenu monthly and fill form when i click on button it will run monthly function which take all values*(from date ,to date,vehicle number)* from form but when i select daily from dropdownmenu it will take only (from date) value and when i click on button it run daily function.


It requires to submit your form with appropriate parameters, that is the only way to call a server side function. You can use Ajax to make it interactive. Hint: Use onchange() event and selectedIndex property of <select>. Good Luck!


Do you mean processing the form in php?

switch ($_POST['aa']) {
  case 'da' : daily($_POST['from_date']); break;
  case 'mo' : monthly($_POST['from_date'], $_POST['to_date'],$_POST['vehicle_number']); break;
  default : echo "Please select a value from the drop-down menu";
}

This of course only if you add method="POST" to your form.


If you want a function switch in Javascript, then do this:

<script>
    dropdown_func = {
        daily: report_daily,       // these are the functions
        monthly: report_monthly    // they should already be defined
    }
<script>

Which can then be invoked in the dropdown with:

<select name="aa" onchange="drowpdown_func[this.value]()"> 
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜