I am using the following code to create a form, that is paginated using java script (that someone on this forum supplied for me, I do not have a lot of experience with Java Script), my understanding is that the JavaScript simply hides\unhides tagged sections of the form.
At the moment, my buttons for the paginated form all look identical, I would like to add some CSS style formatting to highlight the chosen form 'page' number, but my experiments have been unsuccessful so far. Here is my code:
<?php
$PageID = 0;
echo ('<script src="https://code.jquery.com/jquery-1.11.2.js"></script>');
echo ("\n");
echo ('<form>');
foreach ($ListSections as $sections)
{
if ($PageID == 0)
{
echo ('<div id="Page' . $PageID . '" class="informbdy2">');echo ("\n");
}
else
{
echo ('<div id="Page' . $PageID . '" class="informbdy2" style="display:none">');echo ("\n");
}
echo ("<br>");
$PageNum = $PageID +1;
echo ('<p style="cursor:pointer; color:black; background-color: #DBB7BA; border-radius: 8px; border-color: #860A18; padding-left: 6px; padding-right: 6px; "> Section ' . $PageNum . ': ');
echo ($sections[1] . "<br>");
$QuestionNum = 0;
foreach ($ListQs as $value)
{
if ($value[1] == $sections[1])
{
echo ('<div ');
echo ('id="questionsform"');
echo ('name="questionsform"');
echo ('method="post" ');
echo ('action="admin_questions.php"');
echo ('>');
echo ("<input type='hidden' name='MyID' value='" . $value[0] . "'); />");
echo ("<table>");
echo ("<tr>");
echo ("<td>");
echo ("<label for='Question' class='logintext'>Question:</label>");
echo ("</td>");
echo ("<td>");
echo ('<textarea name="Question" rows="2" cols="25">');
echo ("$value[3]");
echo ('</textarea>');
echo ("</td>");
echo ("<td>");
echo ("</td>");
echo ("</tr>");
echo ("<tr>");
echo ("<td>");
echo ("<label for='Answer1' class='logintext'>Answer 1:</label>");
echo ("</td>");
echo ("<td>");
echo ('<textarea name="Answer1" rows="1" cols="25">');
echo ("$value[4]");
echo ('</textarea>');
echo ("</td>");
echo ("<td>");
echo ("<input type='radio' name='" . $QuestionNum . "ans1' value='1' >1");
echo ("</td>");
echo ("</tr>");
echo ("<tr>");
echo ("<td>");
echo ("<label for='Answer2' class='logintext'>Answer 2:</label>");
echo ("</td>");
echo ("<td>");
echo ('<textarea name="Answer2" rows="1" cols="25">');
echo ("$value[5]");
echo ('</textarea>');
echo ("</td>");
echo ("<td>");
echo ("<input type='radio' name='" . $QuestionNum . "ans2' value='2' >2");
echo ("</td>");
echo ("</tr>");
echo ("<tr>");
echo ("<td>");
echo ("<label for='Answer3' class='logintext'>Answer 3:</label>");
echo ("</td>");
echo ("<td>");
echo ('<textarea name="Answer3" rows="1" cols="25">');
echo ("$value[6]");
echo ('</textarea>');
echo ("</td>");
echo ("<td>");
echo ("<input type='radio' name='" . $QuestionNum . "ans3' value='3' >3");
echo ("</td>");
echo ("</tr>");
echo ("</td>");
echo ("</tr>");
echo ("</table>");
echo ('</div>');
echo ('</br>');
echo ('</br>');
}
}
$PageID++;
echo ('</div>');
}
echo ('</div>');
echo ('</form>' ."\n");
?>
<?php
// Create Page Menu's for the form
$PageID = 0;
echo ('<div id="page_menus">' ."\n");
echo ("</br>CLICK TO SELECT PAGE >> ");
foreach ($ListSections as $PageMenu)
{
$mystring = '<a id="get_';
//echo ($mystring);
$mystring = $mystring . $PageID;
//echo ($mystring);
$mystring = $mystring . '" style="cursor:pointer; color:black; background-color: #DBB7BA; border-radius: 8px; border-color: #860A18; padding-left: 6px; padding-right: 6px; ">';
//echo ($mystring);
++$PageID;
$mystring = $mystring . $PageID . '</a>' ."\n";
echo ($mystring);
}
echo ('</div>' . "\n" . '</br>'."\n");
//Script to show and hide each 'Page' of the form
echo ("\n");
$PageID = 0;
?>
<script>
<?php
foreach ($ListSections as $ShowHide)
{
$MyPage = "Page" . $PageID;
$MyGet = "get_" . $PageID;
?>
var my_get = <?php echo json_encode("#" . $MyGet); echo ("\n");
?>;
$(my_get).click(function(){
<?php $OtherPage = 0;
foreach ($ListSections as $Midsections)
{
$ThisPage = "Page" . $OtherPage;
if ($Midsections[1] <> $ShowHide[1])
{
?>
var noshow_page = <?php echo json_encode("#" . $ThisPage);
?>;
$(noshow_page).hide()
<?php
}
else
{
?>
var noshow_page = <?php echo json_encode("#" . $ThisPage);?>;
$(noshow_page).show()
<?php
}
$OtherPage++;
}
?>;
})
<?php
$PageID++;
}
?>
</script>
How would I add CSS type formatting to the page menu items (under the section commented "// Create Page Menu's for the form") to show that a certain 'page' of the form is selected? The problem is that the web-page is not re-loaded, so I cannot simply track the button presses and re-format using 'if' style logic and CSS.
Thank you,
Lee
You would need to add some JS to handle the click and then you can style using CSS.
HTML:
<div id="page_menus">
<a id="get_01">1</a>
<a id="get_02">2</a>
<a id="get_03">3</a>
<a id="get_04">4</a>
<a id="get_05">5</a>
</div>
JS:
jQuery('#page_menus a').on('click', function() {
if ($('a').hasClass('current')) {
$('a').removeClass('current');
}
$(this).addClass('current');
});
CSS:
#page_menus a {
cursor:pointer;
color:black;
background-color: #DBB7BA;
border-radius: 8px;
border-color: #860A18;
padding-left: 6px;
padding-right: 6px;
}
#page_menus a.current {
background-color: #ccc;
}
Here is a working fiddle.
Related
How can I fix this? I have used PHP to display data from my database but I didn't foresee this bug. When I click the edit the modal will appear However, when I click the edit button of the other data the modal will not appear. How can I fix this? What I want is when I click the edit button modal will appear. I hope you can help me its been bugging me for days.
Edit Button.
Please See Modal.
Here is my code:
PHP:
echo "<div class='col-3'>";
echo "<div class='card'>";
echo "<div class='row'>";
echo "<div class='col-2'>";
echo "<h6 class='card-title'>".$row['project_name']."</h6>";
echo "</div>";
echo "<div class='col-2'>";
echo "<div class='card-setting'><i class='fa fa-gear'></i></div>";
echo "<div id='card-setting-dropdown' class='card-dropdown-content'>";
echo "<button class='card-dropdown-menu' id='btn-edit'>Edit Project</button>";
echo "<button class='card-dropdown-menu'>Delete Project</button>";
echo "<button class='card-dropdown-menu'>Add Task</button>";
echo "</div>";
echo "</div>";
echo "</div>";
echo "<div class='row'>";
echo "<div class='col-2'>";
echo "<label class='project-details'>".$row['department']."</label>";
echo "</div>";
echo "<div class='col-2'>";
echo "<label class='project-details' style='float:right;'>Priority: <span style='color:".$color."'>".$row['priority']."</span></label>";
echo "</div>";
echo "</div>";
echo "<div class='pr-task-data'>";
echo "<div class='pr-task-summary-l'>";
echo "<label class='pr-task-title'>Tasks</label>";
echo "<p class='pr-task-details'>".$count_2."</p>";
echo "</div>";
echo "<div class='pr-task-summary-l'>";
echo "<label class='pr-task-title'>Completed</label>";
echo "<p class='pr-task-details'>".$count_3."</p>";
echo "</div>";
echo "<div class='pr-task-summary-l'>";
echo "<label class='pr-task-title'>In-Progress</label>";
echo "<p class='pr-task-details'>".$count_4."</p>";
echo "</div>";
echo "<div class='pr-task-summary-r'>";
echo "<label class='pr-task-title'>Not Completed</label>";
echo "<p class='pr-task-details'>".$count_5."</p>";
echo "</div>";
echo "</div>";
echo "<div class='progress'>";
echo "<div class='progress-bar' style='width:".$percent."%;'>";
echo "<label class='progress-bar-percent'>".$percent."%</label>";
echo "</div>";
echo "</div>";
echo "</div>";
echo "</div>";
echo "<div id='modal_2' class='modal fade'>";
echo "<div class='modal-dialog'>";
echo "<div class='modal-content'>";
echo "<div class='modal-header'>";
echo "<h6 class='modal-title'>Add Project</h6>";
echo "<button type='button' class='close_2'>x</button>";
echo "</div>";
echo "<div class='modal-body'>";
echo "<form autocomplete='off' method='POST'>";
echo "<input type='hidden' id='".$row['project_id']."'>";
echo "<div class='form-group'>";
echo "<label class='form-control-label'>Program</label>";
echo "<input type='text' placeholder='Program' name='program' id='program_2' class='form-control'>";
echo "</div>";
echo "<div class='form-group'>";
echo "<label class='form-control-label'>Project Name</label>";
echo "<input type='text' placeholder='Project Name' name='pname' id='pname' class='form-control'>";
echo "</div>";
echo "<div class='form-group'>";
echo "<label class='form-control-label'>Project Description</label>";
echo "<input type='text' placeholder='Description' name='description' id='description' class='form-control'>";
echo "</div>";
echo "<div class='form-group'>";
echo "<label class='form-control-label'>Department</label>";
echo "<select class='form-control' id='department' name='department'>";
echo "<option value=''>Department</option>";
echo "<option value='Executive Department'>Executive Department</option>";
echo "<option value='CCA Department'>CCA Department</option>";
echo "</select>";
echo "</div>";
echo "<div class='form-group'>";
echo "<label class='form-control-label'>Priority</label>";
echo "<select class='form-control' id='priority' name='priority'>";
echo "<option value=''>Priority</option>";
echo "<option value='Low'>Low</option>";
echo "<option value='Medium'>Medium</option>";
echo "<option valie='High'>High</option>";
echo "<option valie='High'>High</option>";
echo "</select>";
echo "</div>";
echo "</div>";
echo "<div class='modal-footer'>";
echo "<button type='submit' class='btn btn-update' name='update'>Update</button>";
echo "<button type='button' class='btn btn-secondary'>Close</button>";
echo "</div>";
echo "</form>";
echo "</div>";
echo "</div>";
echo "</div>";
SCRIPT:
//Edit Project Modal
var modal_edit = document.getElementById('modal_2');
var btn_edit = document.getElementById("btn-edit");
var span_edit = document.getElementsByClassName("close_2")[0];
btn_edit.onclick = function() {
$(modal_edit).toggleClass("modal-show");
}
span_edit.onclick = function() {
$(modal_edit).removeClass("modal-show");
}
$(".btn-secondary").click(function() {
$(modal_edit).removeClass("modal-show");
});
Try something like this.
Add a common class to your edit button Like class="btnEdit other_classes"
Try this code
var modal_edit = document.getElementById('modal_2');
var span_edit = document.getElementsByClassName("close_2")[0];
// I assumed that your button is added dynamically
$(document).on('click',".btnEdit",function(){
$(modal_edit).toggleClass("modal-show");
});
span_edit.onclick = function() {
$(modal_edit).removeClass("modal-show");
}
$(".btn-secondary").click(function() {
$(modal_edit).removeClass("modal-show");
});
Your Click is not working for other elements because you are using id to assign events with them but and id must be unique. I made sample fiddle with two elements with the same ID's and try to look at their difference..
$("#first").click(function(){
alert("I was clicked");
});
div{
display:inline-block;
width:100px;
height:100px;
border:1px solid red;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div id="first">DIV</div>
<div id="first">DIV</div>
The first one only works.. So use class instead..
So i am trying to display data in sql server using PHP. I am using a sortable library i found online and this is my code:
echo "<table id='report' class='sortable'>";
echo "<thead><tr>";
echo "<th>A</th>";
echo "<th>B</th>";
echo "<th>C</th>";
echo "<th>D</th>";
echo "<th>E</th>";
echo "<th>F</th>";
echo "<th>G</th>";
echo "<th>H</th>";
echo "<th>I</th>";
echo "</tr></thead>";
echo "<tbody>";
for($i=0; $i<$tablerows; $i++)
{
echo "<tr>";
echo "<td>".$result[$i]['A']."</td>";
echo "<td>".$result[$i]['B']."</td>";
echo "<td>".$result[$i]['C']."</td>";
echo "<td>".$result[$i]['D']."</td>";
echo "<td>".$result[$i]['E']."</td>";
echo "<td>".$result[$i]['F']."</td>";
echo "<td>".$result[$i]['G']."</td>";
echo "<td>".$result[$i]['H']."</td>";
echo "<td>".$result[$i]['I']."</td>";
echo "<td><div class='arrow'></div></td>";
echo "</tr>";
echo "<tr>";
echo "<td colspan='5'>";
echo "<div id='nestedAccordion'>";
echo "<h2>COLUMN 1 ELABORATE</h2>";
echo "<div>";
echo "</div>";
echo "<h2>COLUMN 2 ELABORATE</h2>";
echo "<div>";
echo "</div>";
echo "<h2>COLUMN 3 ELABORATE</h2>";
echo "<div>";
echo "</div>";
echo "<h2>COLUMN 4 ELABORATE</h2>";
echo "<div>";
echo "</div>";
echo "<h2>COLUMN 5 ELABORATE</h2>";
echo "<div>";
echo "</div>";
echo "</div>";
echo "</td>";
echo "</tr>";
When my page is loaded, it can be sorted by the A-I headings in <th> tag. As you can see, in my 'for' loop my last tag has an arrow. I want that so if the user wants more information about the row, he can view that by clicking that arrow, and information that will be displayed is in: <td colspan='5'>
Here is the javascript/jquery:
$(document).ready(function () {
$("#report tr:odd").addClass("odd");
$("#report tr:not(.odd)").hide();
$("#report tr:first-child").show();
$(".arrow").click(function(){
$(this).parents("tr").next("tr").toggle();
$(this).toggleClass("up");
});
var parentDivs = $('#nestedAccordion div'),
childDivs = $('#nestedAccordion h3').siblings('div');
$('#nestedAccordion h2').click(function () {
parentDivs.slideUp();
if ($(this).next().is(':hidden')) {
$(this).next().slideDown();
} else {
$(this).next().slideUp();
}
});
$('#nestedAccordion h3').click(function () {
childDivs.slideUp();
if ($(this).next().is(':hidden')) {
$(this).next().slideDown();
} else {
$(this).next().slideUp();
}
});
});
The question and the problem i have is only either sortable for table or arrow will work. When i load the page, and i click on the arrow to view more information i can view it, but if i sort afterward, the data under the arrow is taken as its own row rather than part of the row it was selected from.
If i sort at start, and then click on arrow, the row below is hidden. I think the problem is in this chunk of code:
$(".arrow").click(function(){
$(this).parents("tr").next("tr").toggle();
$(this).toggleClass("up");
});
Since the next tr is for colspan? But how do i fix it?
A section of my code is as follows,
foreach( $alpha as $key => $obj)
{
echo "<tr>";
echo "<td> ". $obj[$d] ."</td>";
echo "<td> ". $obj[$a] ."</td>";
echo "<td> ". $obj[$o] ."</td>";
echo "<td> ". $obj[$f] ."</td>";
echo "<td> ". $obj[$e] ."</td>";
echo "</tr>";
}
Here the array alpha is an associative array. The $d, $a, $o, $f, $e are the row values from an sql query. I want to check the value in the $obj[$f] and if a value exists then alert the user using javascripts' alert() command, that a value exists and if it doesnt then i want the looping to continue as usual.
try this
foreach( $alpha as $key => $obj){
if(!empty($obj[$f])){
//has value, echo alert
echo "<script>alert('object f contains value')</script>";
} else {
//no value there so echo rest of table
echo "<tr>";
echo "<td> ". $obj[$d] ."</td>";
echo "<td> ". $obj[$a] ."</td>";
echo "<td> ". $obj[$o] ."</td>";
echo "<td> ". $obj[$f] ."</td>";
echo "<td> ". $obj[$e] ."</td>";
echo "</tr>";
}
}
Can try this:
foreach( $alpha as $key => $obj)
{
if(isset($obj[$f]) && !empty($obj[$f]))
{
echo "<script>alert('your comment')</script>";
exit;
}
else
{
echo "<tr>";
echo "<td> ". $obj[$d] ."</td>";
echo "<td> ". $obj[$a] ."</td>";
echo "<td> ". $obj[$o] ."</td>";
echo "<td> ". $obj[$f] ."</td>";
echo "<td> ". $obj[$e] ."</td>";
echo "</tr>";
}
}
I have created a test page called syndication.php where mysql data is being created in an Atom feed like this:
<feed xmlns="http://www.w3.org/2005/Atom">
<title>Fishing Reports</title>
<subtitle>The latest reports from apporan.com</subtitle>
<link href="http://www.apporan.com/reports" rel="self"/>
<updated><?php echo date3339(); ?></updated>
<author>
<name>Smithers</name>
<email>smithers#fishinhole.com</email>
</author>
<id>tag:apporan.com,2015:http://www.apporan.com/syndication.php</id>
<?php
$i = 0;
while($row = mysql_fetch_array($result))
{
if ($i > 0) {
echo "</entry>";
}
$articleDate = $row['posted'];
$articleDateRfc3339 = date3339(strtotime($articleDate));
echo "<entry>";
echo "<title>";
echo $row['title'];
echo "</title>";
echo "<link type='text/html' href='http://www.apporan.com/reports/report.php?id=".$row['id']."'/>";
echo "<id>";
echo "tag:apporan.com,2015:http://www.apporan.com/reports/report.php?id=".$row['id'];
echo "</id>";
echo "<updated>";
echo $articleDateRfc3339;
echo "</updated>";
echo "<author>";
echo "<name>";
echo $row['author'];
echo "</name>";
echo "</author>";
echo "<summary>";
echo $row['subtitle'];
echo "</summary>";
$i++;
}
?>
</entry>
</feed>
Although this is doing the job. I want to parse/embed this to mye page. Can anyone help me?enter code here
Im trying to get a value of an input into my buttons action url before the button is pushed.
I need to get the value of:
id="qty<?php echo $i;?>"
Into where it says:
<?php echo VALUE OF $qtyforaction; ?>
My Code is:
<?php $i = $_product->getId();?>
<form action="<?php echo $this->helper('checkout/cart')->getAddUrl($_product); ?>" method="post" id="product_addtocart_form_<?php echo $_product->getId()?>"<?php if($_product->getOptions()): ?> enctype="multipart/form-data"<?php endif; ?>>
<input type="text" name="qty" id="qty<?php echo $i;?>" maxlength="12" value="1" title="Qty" class="cartnum" />
<?php $qtyforaction = 'qty'.$i; ?>
<?php echo $qtyforaction; ?>
<button type="button" class="addtocartbutton button btn-cart" onclick="setLocation('<?php echo $this->helper('checkout/cart')->getAddUrl($_product); ?>qty/<?php echo VALUE OF $qtyforaction; ?>')" ><span><span>Order Again</span></span></button>
</form>
Would I have to use javascript to get it into the url string? My javascript is a bit ropey, would something like this work?
<script type="text/javascript">
var something= document.getElementById('<?php echo $qtyforaction;?>');
</script>
UPDATE WITH FULL CODE:
<?php
if (Mage::getSingleton('customer/session')->isLoggedIn()) {
/* Get the customer data */
$customer = Mage::getSingleton('customer/session')->getCustomer();
/* Get the customer's email address */
$customer_email = $customer->getEmail();
}
$collection = Mage::getModel('sales/order')->getCollection()->addAttributeToFilter('customer_email', array(
'like' => $customer_email
));
$uniuqProductSkus = array();
foreach ($collection as $order) {
$order_id = $order->getId();
$order = Mage::getModel("sales/order")->load($order_id);
$ordered_items = $order->getAllItems();
foreach ($ordered_items as $item)
{
if (in_array($item->getProduct()->getSku(), $uniuqProductSkus)) {
continue;
} else {
array_push($uniuqProductSkus, $item->getProduct()->getSku());
$_product = Mage::getModel('catalog/product')->load($item->getProductId());
$product_small_image_path = Mage::helper('catalog/image')->init($_product, 'small_image')->resize(200);
$product_thumbnail_path = Mage::helper('catalog/image')->init($_product, 'small_image')->resize(150);
$summaryData = Mage::getModel('review/review_summary')->load($item->getProductId());
echo "<li>";
echo "<div class='previous-name'><p><a style='color:black; font-weight:bold; font-size:14px;' href='" . $_product->getProductUrl() . "'>";
echo $item->getName() . "</a></p></div>";
echo "<div class='previous-image'><a href='" . $_product->getProductUrl() . "'>";
echo "<img src='" . $product_small_image_path . "' />";
echo "</a></div>";
echo "<div class='previous-rating'>";
echo "<p><a style='color:black; font-weight:bold; font-size:14px;' href='" . $_product->getProductUrl() . "#product_tabs_review_tabbed'>Review this beer now</a></p>";
echo $summaryData->getRatingSummary() . '% Would buy again <br/>';
echo "<div class='rating-box' style='float:left;'>";
echo "<div class='rating' style='width:" . $summaryData->getRatingSummary() . "%'></div></div>";
echo "</div>";
/**echo "<div class='previous-button'>";
echo '<button type="button" title="Add to Cart" class="button btn-cart" onclick="setLocation(\'';
echo $this->helper('checkout/cart')->getAddUrl($_product);
echo '\')"><span><span>Order Again</span></span></button>';
echo "</div>";**/
?>
<?php $i = $_product->getId();?>
<div class='previous-button'>
<form action="<?php echo $this->helper('checkout/cart')->getAddUrl($_product); ?>" method="post" id="product_addtocart_form_<?php echo $_product->getId()?>"<?php if($_product->getOptions()): ?> enctype="multipart/form-data"<?php endif; ?>>
<input type="text" name="qty" id="qty<?php echo $i;?>" maxlength="12" value="1" title="Qty" class="cartnum" />
<?php $qtyforaction = 'qty'.$i; ?>
<script type="text/javascript">
var xy = document.getElementsByTagName("input")[0].getAttribute("qty");
var x = "<button type='button' class='addtocartbutton button btn-cart' onclick='setLocation()'><span><span>Order Again</span></span></button>";
document.getElementById("buttonaddcart").innerHTML = x;
</script>
<div id="buttonaddcart">
<button type="button" class="addtocartbutton button btn-cart" onclick="setLocation('<?php echo $this->helper('checkout/cart')->getAddUrl($_product); ?>qty/')" ><span><span>Order Again</span></span></button>
</div>
</form>
</div>
<?php
echo "<div class='previous-clear'></div>";
echo "</li>";
}
}
}
?>
You need to get the value of the id attribute:
var x = document.getElementsByTagName("input")[0].getAttribute("id");
But how do you plan on using PHP to echo out this variable if PHP is loaded and done with before Javascript even comes into play? You could use Javascript though to display this variable on the page if that's all you needed.
If you had something in your HTML to target, you could do it like this:
document.getElementById("result").innerHTML = x;
But anyways, get the action attribute value...
var y = document.getElementsByTagName("form")[0].getAttribute("action");
Then set the action attribute to this + the qty...
document.getElementsByTagName("form")[0].setAttribute("action", x + y);
That should work for you, if not, try wrapping x + y in additional parentheses...("action", (x + y));