Jump to content

jquery command overwritten after adding PHP codes


genzedu777

Recommended Posts

Hi,

 

Currently the line which I have highlighted in red, was actually a jquery command, which prompt user if there is no selection, it was originally meant to be in a html code, but I have added into a php coding, and after I have run it, when there is no selection, the system will not prompt the user anymore, it seems like by putting it into the PHP coding, it overwrites the jquery command. Any advice to this? Thanks

 

 

<?php

$dbc = mysqli_connect('localhost', '***', '***', '***')

or die(mysql_error());

$query = ("SELECT * FROM tutor_preferred_district ORDER BY district_id ASC");

$sql = mysqli_query($dbc, $query)

or die(mysql_error());

while($data = mysqli_fetch_array($sql))

{

echo '<input name="district" type="checkbox" id="'.$data['district_id'].'" value="'.$data['district_id'].' class="required" title="Please check at least 1 location.">

<label for="'.$data['district_id'].'">'.$data['district_name'].'</label>';

}

?>

 

 

<html>

<input name="district" type="checkbox" id="1" value="1" class="required" title="Please check at least 1 location.">

      <label for="1">Yishun</label>

 

</html>

Missing a double-quote in the HTML tag, plus a single quote at the end of the echo

echo '<input name="district" type="checkbox" id="'.$data['district_id'].'" value="'.$data['district_id'].'" class="required" title="Please check at least 1 location.">';

php and JavaScript (jQuery being your choice of JavaScript framework in this case) do no interact. They are completely independent of one another, you can not call a function from a JavaScript element with PHP and vise versa. PHP renders server side and displayes to the client the finished product of that rendition. JavaScript can take that finished rendition and remaster it, anything from the alerts, to altering the physical appearance.

 

Also the bit in red is technically more in tune with CSS than it is jQuery.. but thats the part of JavaScript/jQuery that manipulates the front end after its been rendered. I don't recall ever seeing an input checkbox with a "Title" either.

 

 

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.