将值从一个字段传递到另一个字段

时间:2012-06-18 06:27:31

标签: php

我是编程语言的新手。我想知道我可以从其他字段获取价值并以相同的形式传递给其他字段而不使用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();
    }); 

}   

并且我无法在PHP代码中获得值返回,因为我通过jQuery传递值。

1 个答案:

答案 0 :(得分:1)

不,你不能。进行交互式操作的唯一方法是使用javascript进行操作,如果您要查看它。如果无关紧要,可以在服务器上执行此操作,方法是将第二个变量赋值为第一个。