0

I have a dropdown where the user selects the Week Number. If the selected week is not presented in the database then "Not Done" has to be displayed and if the selected Week is present then it has to display "Done"

//JavaScript function

function onchangeval(){

}  

//PHP 

<?php

$date_string = date('Y-m-d');

if(!isset($_GET['week'])) {
$_GET['week'] = $currentweekno;
}

$sql   = "SELECT distinct Import as Import FROM info_table where Import = '".$date_string."' and Week(Import) <= '".$currentweekno."' ";

//$currentweekno is the user modified CW from the drop down (dynamic - am not sure)

$adddetails = mysql_query($sql);
$adddetails = mysql_fetch_assoc($adddetails);

if ($adddetails['Import'] != ''){
    $title1="Done";
}else if ($adddetails['Import'] == ''){
    $title1="Not Done";
}

?>

<td>
 CW:
 <select name="week" id="week" style="width: 100px" onchange="return onchangeval(); >
 <option value="">--Select--</option>
 <?php for($i=1;$i<=53;$i++) {?>
 <option value="<?php echo $i;?>"  <?php echo @$_GET['week'] == $i ? "selected" : "";?> ><?php echo $i;?></option>
 <?php }?>
 <option value="1">1</option>
 </select>
</td>

<td>    
<span class='u' style='color: red'><b><?php echo $title1;?></b></span>
</td>

Am struck at this point, can anyone guide me here on how to do this

5
  • 2
    This is not possible. PHP is executed on the server side and JS on the client side. Commented Oct 17, 2018 at 8:35
  • 2
    You can create a AJAX request though, and send the request to the server side. Commented Oct 17, 2018 at 8:36
  • @AyushGupta, i can try this with Ajax right? Commented Oct 17, 2018 at 8:36
  • See also stackoverflow.com/questions/13840429/… Commented Oct 17, 2018 at 8:36
  • But yes, if you need to invoke some PHP from JavaScript without posting back your entire page, you need to use an AJAX request. Commented Oct 17, 2018 at 8:37

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.