2012-06-18 152 views
0

我是新来的编程语言。我想知道我可以从其他领域的价值,并传递到其他领域的相同形式,而不使用JavaScript?有人可以向我解释吗?谢谢你。将值从一个字段传递到另一个字段

这是我的表单页面

<form id="leave_form"> 
<table><tr> 
<td width="70"><b>*</b> Date From:</td> 
<td width="120"><span id="lv_date_from_btn"><input readonly class="field_required control" onchange="validateLeave('from')" id="lv_date_from" name="date_from" value="<?php echo $start_date?>" size="10" maxlength="10"/> <img src="images/calendar.gif"/></span></td> 
</tr> 
<tr> 
<td width="70"><b>*</b> Date To:</td> 
<td width="120"><span id="lv_date_to_btn"><input readonly class="field_required control" onchange="validateLeave('to')" id="lv_date_to" name="date_to" value="<?php echo $end_date?>" size="10" maxlength="10"/> <img src="images/calendar.gif"/></span></td> 
</tr> 

<?php if ($userid == '609'):?> 
<tr> 
<td><b>*</b> Relief Staff: </td> 
<td> 

<select name="userid" id="frm_userid2" class="field_required control" onchange="validateLeave('relief')" >  
<?php 
$leavefrom = $_REQUEST['from']; 
$leaveto = $_REQUEST['to']; 
if (empty($leavefrom)) 
{ 
echo '<option value="" selected disabled>Select...</option>'; 
} 
else{ 
echo '<option value="" selected disabled>Select...</option>';     
$sql = " 
SELECT distinct fullname FROM core_user LEFT JOIN lms_tran ON lms_tran.userid = core_user.userid where core_user.userid NOT IN (SELECT userid FROM lms_tran WHERE date_from BETWEEN '$leavefrom' AND '$leaveto' AND app_status = 'Approved') AND core_user.userid != 609 AND core_user.status = 'Y' ORDER by fullname ASC 
       "; 

$result = mysql_query($sql); 

while ($row = mysql_fetch_assoc($result)) 
{      
echo '<option value="'.$row["userid"].'">'.$row["fullname"].'</option>';      
} 
}?> 
</select> 
</td> 
</tr> 
<?php endif; ?> 
    </table> 
    </form> 

,这是JavaScript的

function validateLeave(type) 
{ 
    var days= jQuery('#frm_days').val(); 
    var from = jQuery('#lv_date_from').val(); 
    var to = jQuery('#lv_date_to').val(); 
    var relief = jQuery('#frm_userid2').val(); 

    if (type != 'check') 
    { 
     days_incorrect = true; 
    }  
    if (type == 'days' || type == 'from') 
    { 
     to = ''; 
     relief = ''; 
    } 
    if (type == 'to') 
    { 
     days = ''; 
    }  

    if ( 
     (
     (days == '' ? 0 : 1) + 
     (to == '' ? 0 : 1) + 
     (from == '' ? 0 : 1)   
     ) < 2 
    ) 
    { 
     days_correct = false; 
     return; 
    } 

    days = parseFloat(days); 
    jQuery('#frm_days').val(days); 
    jQuery('.control').attr('disabled', true); 
    jQuery('#lv_loading').show();  
    jQuery.post('index.php?_m=lms&_a=leave_validate&from='+from+'&to='+to, {from:from,to:to,days:days}, function(res){ 
     eval('var r = '+res+';'); 
     if (r.status == 'OK') 
     { 
      days_incorrect = false; 
      if (r.to) 
      { 
       jQuery('#lv_date_to').val(r.to); 
      } 
      if (r.from) 
      { 
       jQuery('#lv_date_from').val(r.from); 
      } 
      if (r.days) 
      { 
       jQuery('#frm_days').val(r.days); 
      } 
     }   
     else if (r.status == 'HOLIDAYERROR') 
     { 
      alert('Incorrect leave start date. Leave start date can not fall into Weekend or Public Holidays'); 
      days_incorrect = true; 
     } 
     else 
     { 
      alert('Incorrect leave period. Please check back Leave Start, Leave End and Leave Days') 
      days_incorrect = true; 
     } 
     jQuery('.control').attr('disabled', false); 
     jQuery('#lv_loading').hide(); 
    }); 

} 

和我could'nt得到PHP代码的价值回归,因为我HV通过jQuery传递价值。

+0

为什么你需要这个? –

+0

你是什么意思的字段,解释更多或张贴phsedo代码。 – Sarfraz

+0

我的意思是在表单中我有几个输入文本,我想从文本字段的值传递到第二个输入文本字段之前提交.. –

回答

1

不,你不能。做互动的唯一方法是用javascript来做,如果你看到它的话。如果无关紧要,您可以通过为第二个变量分配第一个变量来在服务器上执行此操作。

+0

好的谢谢,但你可以检查我的代码上面,我试图获得值..它仍然返回空.. –

相关问题