I have this PHP file:
foreach($allfiles as $file) {
echo '<div class="file" id="file' . $file->id . '">';
echo '<div id="checkbox"><img src="images/delete.png" width="15" height="15"></img></div>';
echo '<div id="filename">'. $file->name . '</div>';
echo '<div id="size">| '. $file->size . ' </div>';
echo '<div id="created">'. $file->created . '</div>';
echo '<div id="download"><img src="images/download.png" width="18" height="18"></img></div>';
echo '</div>';
?>
<script>
var id = <?php echo $file->id; ?>
</script>
<?php
}
and this JS file
$('#file' + id).dblclick(function() {
alert(1);
});
What I'm trying to do is that when div "file" + the file id is clicked, it will alert "1" (or open the file).
The problem is that now it only alerts 1 when I doubleclick the last div I have, while it is supposed to be done on all of them.
Is there a solution like foreach div called file + something do ? when doubleclicked.
Sorry if this was very unclear :D
You can use data-* prefixed custom attribute like
echo '<div class="file" data-id="' . $file->id . '">';
Bind your event using the common class and then fetch data-idusing .data()
$('.file').on('dblclick', function() {
alert($(this).data('id'));
});
Related
I'm not a php developer and I have a basic knowledge in html.
I currently have this code
<div class="page-header">
<h1 class="<?php echo $this->item->backlink ? "backlink" : ""; ?>">
<?php echo $this->item->backlink ? '<a class="backtomap" href="' . $this->item->backlink . '">' . JText::_('COM_FOCALPOINT_BACK_TO_MAP') . '</a>' : "";
echo trim($this->item->title); ?>
</h1>
</div>
now I want to integrate the history.back function in place of the current
onclick="history.back(-1)"
so that the generated html looks something like
<a class="backtomap" href="#" onclick="history.back(-1)>' . JText::_('COM_FOCALPOINT_BACK_TO_MAP') . '</a>'
I tried to change the code here and there, but without the right knowledge it doesn't really work.
Can anybody help?
Thank you.
Just Change line
'<a class="backtomap" href="' . $this->item->backlink . '">' . JText::_('COM_FOCALPOINT_BACK_TO_MAP') . '</a>'
with
'<a class="backtomap" href="#" onclick="history.back(-1)" >' . JText::_('COM_FOCALPOINT_BACK_TO_MAP') . '</a>'
In my PHP I have a line of JSON:
echo '"jsoncaption":"'.$xxx.' '.$yyy.' <br /> ('.$zzz.')",';
I want to have the text line-height: 110%;, so I do this:
echo '<div style=\'line-height: 110%;\'>';
echo '"jsoncaption":"'.$xxx.' '.$yyy.' <br /> ('.$zzz.')",';
echo '</div>';
But this causes an an error in my JS console!
Unexpected token < in JSON at position 55
Without the <div> everything works, but I want to use line-height.
Someone have an idea?
echo '"jsoncaption":"' . '<div style=\'line-height: 110%;\'>' . $xxx .' '.$yyy.' <br /> ('.$zzz.')</div>",';
What did I do?
This would be a more detailed script:
$content = $xxx.' '.$yyy.' <br /> ('.$zzz.')';
$wrapped_content = '<div style=\'line-height: 110%;\'>' . $content . "</div>";
echo '"jsoncaption":"' . $wrapped_content . '",';
EDIT: Untested of course, maybe some quotation marks are wrong...
I am looking to add blog details to the following dropdown list to replace $site['domain'] in the option value with the detail 'blogname'. I also want to keep $site['domain'] in the option content.
function blavou_existing_sites() {
echo '<div id="blav-wrapper">';
echo '<div class="blav-nav-wrapper">';
echo '<ul class="blav-drop">';
echo '<form action="../">';
echo '<select name="mySelectbox" id="mySelectbox">';
echo '<option value="">Choose Existing</option>';
$sites = wp_get_sites();
foreach ($sites as $site) {
printf( '<option value="http://'.$site['domain'].'/wp-admin/">'.$site['domain'].'</option>');
}
echo '</select>';
echo '<input type="button" onclick="window.open(this.form.mySelectbox.options[this.form.mySelectbox.selectedIndex].value,\'_top\')" value="Confirm">';
echo '</form>';
echo '</ul>';
echo '</div>';
echo '</div>';
}
Help Appreciated!
You can use the get blog details() function:
foreach ($sites as $site) {
$details = get blog details($site['blog_id']);
printf( '<option value="%s">%s (%s)</option>', 'http://'.$site['domain'].'/wp-admin/', $details->blogname, $site['domain'] );
}
This should give you options like "blogname (url)".
I am currently trying to modify a plugin that was made for get simple cms. The plugin is called "pages with comments". The reason I am posting here is because the topic for the plugin in the forums looks to be dead. Here is the link to the plugin I am currently using. https://mega.co.nz/#!pVcRnTiI!N0SyhLXrPbE1vFH3dNBaqO0zznETDD--QQpWp0c1EJoI have modified it but so you can see what code I am working with I am uploading it as a zip. My question is how do I make a a field required so when users submit the comment there has to be something in it. Either that or make that field a drop down.
Thanks
if ($capt =='Y'){
echo '<div id="captch"> ';
echo '<img alt="" class="capt" id="captcha'.$imfin.'" src="'.$siteurl.'plugins/pages_comments/img_cpt.php?url='.GSPLUGINPATH.'pages_comments/" />';
echo '<input type="button" value="'.$i18n['reload'].'" onClick="javascript:rec_cpt("captcha'.$imfin.'","'.$siteurl.'plugins/pages_comments/img_cpt.php?url='.GSPLUGINPATH.'pages_comments/")" /> <span class="msgavs">'.$i18n['rl'].'</span>';
echo '</div>';
echo '<div class="cap_input">';
echo '<input type="text" value="" name="guest[pot]" /><span>'.$i18n['Cpt'].'('.$i18n['Rf'].']'.'</span>';
echo '</div>';
}
echo '<div class="submit">';
echo '<input type="submit" value="'.$i18n['Ev'].'" name="guest-submit" />';
echo '</div>';
if (empty($_POST["field_name"])) {
$FieldErr = "FIELD is required"; //or any other error message
} else {
// code for submitting;
}
// you can dispaly the error message using echo $FeildErr beside your field area
Ok , so i am using colorbox to pop up windows of dynamic data generated by PHP .. Below is my php code ... when I click on the link , the windows pop up with the data .... but if I click on the same link again , the window doesn't get the information and I get this in the console a.removeEventListener is not a function , for the second time on clicking on the link for the colorbox to show .. 1st time works .. what could be going wrong ?
jQuery(document).ready(function() {
var id_form;
var url;
$("a.madcomment").click(function(e) {
e.preventDefault();
id_form = $(this).attr('id');
url ="#madcomment_menu"+id_form;
$("a.madcomment").colorbox({inline:true, width:"350px", href:url});
});
});
<?php
$select = "SELECT * FROM COMMENTS INNER JOIN Twitter_Data ON Twitter_Data.screen_name=Comments.Twitter WHERE Category ='Comments'";
$result = mysql_query($select);
$result_count = mysql_num_rows($result);
echo " <table border =\"0\">";
echo "<tr>";
$user_array = array();
$counter = 0;
if($result_count > 0) {
while ($row = mysql_fetch_array($result, MYSQL_ASSOC)) {
echo "<div id ='scoring_scale' class='madscore".$row['ID']."' style='display:none;'>";
echo "<div id='madcomment_menu".$row['ID']."' style='padding:10px; background:#fff;'>";
echo "<a id='".$row['ID']."' class='green_circle' href='#'> +3 </a>";
echo "<a id='".$row['ID']."' class='orange_circle' href='#'> +1 </a>";
echo "<a id='".$row['ID']."' class='red_circle' href='#'> -1 </a>";
echo "<a id='".$row['ID']."' class='brown_circle' href='#'> -3 </a><br />";
echo"<form>";
echo "<textarea id='text".$row['ID']."'rows='5' cols='33'>";
echo "-";
echo "</textarea>";
echo"<button id='button".$row['ID']."'class='button_madscore'> MadComment </button>";
echo "</form>";
echo "</div>";
echo "</div>";
}
}
// Here is the link that will generate the COLORBOX pop-up
echo "<a id='".$row['ID']."'class=' madcomment' href='madcomment_menu".$row['ID']."'><img src='images/madcomment.png' /> </a>";
?>
You are binding your colorbox each time on anchor click so in order to prevent this replace you colorbox code with below :
$.fn.colorbox({inline:true, width:"350px", href:url});
This will fix your issue.