简体   繁体   中英

Passing value from one field to another field

I'm new to programming language. I want to know can i get value from other field and pass to other field in same form without using javascript ? Can someone explain to me ? Thank u.

This my form page

<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> 

and this is 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();
    }); 

}   

and i could'nt get the value return in php code as i hv pass value via jQuery.

No, you can't. The only way to do something interactive is to do it with javascript if you the to see it. If it doesn't matter you can do this on the server by assigning the second variable with the value of the first.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM