Mounica Yelchuri Mounica Yelchuri - 7 months ago 20
PHP Question

how to take computed values into javascript

<h1>Job posts</h1>
<?php foreach ($company as $com){?>
<h1><?php echo $com[0];?>'s Profile</h1><?php ?>
<h4>Job Details</h4>
<p>Designation: <?php echo $com[1];?></p>
<p>package: <?php echo $com[2];?></p>
<p>Posting Location: <?php echo $com[3];?></p>
<p>Test date: <?php echo $com[4];?></p>
<h4>Student Requirements</h4>
<p>Branch: <?php echo $com[5];?></p>
<p>CGPA: <?php echo $com[6];?></p>
<p>Twelfth Percentage: <?php echo $com[7];?></p>
<p>Tenth Percentage: <?php echo $com[8];?></p>
<p>Year Of Passing: <?php echo $com[9];?></p>
<p>Number of Backlogs allowed: <?php echo $com[10];?></p>
<?php
$user_id=$session_user_id;
$data=user_data($session_user_id,'user_id','email');
$comp_data=get_job_data($com[11],'comp_id','branch','cgpa','tenth_per','twelfth_per','btech_year','backlogs');
while ($row= mysqli_fetch_assoc($comp_data)){
$branch=$row['branch'];
$cgpa=$row['cgpa'];
$tenth_per=$row['tenth_per'];
$twelfth_per=$row['twelfth_per'];
$btech_year=$row['btech_year'];
$backlogs=$row['backlogs'];
}
$students=eligibile_students($com[11],$branch,$cgpa,$tenth_per,$twelfth_per,$btech_year,$backlogs);
$email=$data['email'];
$check=0;
foreach($students as $s)
{
if(strcmp($email,$s)==0)
{
echo "student is eligible";
$check=1;?>
<form >
<input type="button" value="apply now" onclick="msg()">
</form>
<?php }
}
if($check==0)
{
echo "not eligible";
}
?>

<script>
function msg() {
var check="<?php echo $email?>";
window.alert(check);

}
</script>
<?php }?>


this code first displays job posts available and checks students eligible for that particular company and also checks whether particular student is eligible or not.. now task remaining is when student clicks on apply now button ..name of company and email should be passed to msg() function. how can i do this?

Answer

You can pass the email and company name into msg() by including parameters in the function call.

The Button

I don't know which index in $com contains the company's name. You may need to adjust the index in $com[0] as used below.

<input type="button" value="apply now" onclick="msg('<?= $email ?>', '<?= $com[0]?>')">

The JavaScript

<script>
    function msg(email, companyName) {
        var check = "<?php echo $email?>";
        window.alert(check);

        //do something with email
        alert(email);

        //do something with companyName
        alert(companyName);
    }
</script>