How to Convert PHP to jQuery
Help me guys to convert this into jQuery. It works fine but I want to convert this in to jQuery. I tried several ways but it didn't work :( Here is my code.....................................................................................................................................................
<?php
$f_pId = $_GET['f_pId'];
$f_pName = $_GET['f_pName'];
$f_pStock = $_GET['f_pStock'];
$f_pPrice = $_GET['f_pPrice'];
echo "$f_pId, $f_pName, $f_pStock, $f_pPrice";
$xml = new DomDocument('1.0','UTF-8');
$xml->formatOutput = true;
$xml->preserveWhiteSpace = true;
$xml->Load('products.xml');
$allProducts = $xml->getElementsByTagName('product');
$exist= 0;
foreach ($allProducts as $eachtProduct) {
$pId = $eachProduct->getElementsByTagName('pId');
if($f_pId == $pId->item(0)->nodeValue){
$exist= 1;
break;
}
}
if($exist== 1){
echo "<br />Product Already exists.";
header("refresh:3,url=simpleDomWithPhp3L.php");
}else{
$nProduct = $xml->createElement('product');
$npId = $xml->createElement('pId',$f_pId);
$npName = $xml->createElement('pName',$f_pName);
$npStock = $xml->createElement('pStock',$f_pStock);
$npPrice = $xml->createElement('pPrice',$f_pPrice);
$nProduct->appendChild($npId);
$nProduct->appendChild($npName);
$nProduct->appendChild($npStock);
$nProduct->appendChild($npPrice);
$productList = $xml->getElementsByTagName('productList');
$productList->item(0)->appendChild($nProduct);
if($xml->save('products.xml')){
echo "<br />Product Added.";
header("refresh:3,url=simpleDomWithPhp3L.php");
}else{
echo "<br />errer";
header("refresh:3,url=simpleDomWithPhp3L.php");
}
}
?>
See also questions close to this topic
-
Only toggle certain elements based on class
I have a simple table:
<table> <tr class="header"> <th> .... </th> </tr> <tr class="level2"> <th> .... </th> </tr> <tr class="level3"> <th> .... </th> </tr> <tr class="level3"> <th> .... </th> </tr> <tr class="level2"> <th> .... </th> </tr> <tr class="level3"> <th> .... </th> </tr> <tr class="level3"> <th> .... </th> </tr> </table>
This works great to toggle everything from one "header" to the next.
$('.header').click(function () { $(this).nextUntil('tr.header').toggle(); });
But what I can't figure out how to do is to ONLY toggle the elements with class of "level2" and leave "level3" hidden.
I've been playing around for a while with .toggleClass() and .netAll() but I am not getting it.
-
Unable to change the div color dynamically using VueJS
I am developing an application using Bootstrap and VueJS.
I am developing a Google drive like folder structure, wherein I want to highlight a div in blue when it is selected.
Here is the code:
export default{ mounted(){ $(document).ready(function () { let that = this; $("#div").on("click", ".folderRectangle", function () { $(that).css("background-color", "blue"); $(".folderRectangle").not(that).css("background-color", "white"); }); }); } }
.folderRectangle { x: 220px; y: 473px; width: 299px; height: 62px; background-color: #FFFFFF; border: 1px solid #BDBDBD; border-radius: 0px; }
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script> <script src="https://cdnjs.cloudflare.com/ajax/libs/vue/2.5.17/vue.js"></script> <div class="row"> <div class="col-xl-3 col-md-6"> <stats-card> <div slot="header" class="folderRectangle" id="div"> <div class="row"> <div class="col-3"> <div class="clearfix"> <i class="material-icons" id="folder-image"></i> </div> </div> <div class="col-9"> <div class="clearfix" style="position: relative"> <div> <p style="text-align: left">Folder Name</p> </div> <div> <p style="text-align:left">20 files</p> </div> </div> </div> </div> </div> </stats-card> </div> <div class="col-xl-3 col-md-6"> <stats-card> <div slot="header" class="folderRectangle" id="div"> <div class="row"> <div class="col-3"> <div class="clearfix"> <i class="material-icons" id="folder-image"></i> </div> </div> <div class="col-9"> <div class="clearfix" style="position: relative"> <div> <p style="text-align: left">Folder Name</p> </div> <div> <p style="text-align:left">20 files</p> </div> </div> </div> </div> </div> </stats-card> </div> </div>
When I try clicking on the div, I am unable to change the css color of the div using onClick. What wrong am I doing? Can someone please help me out?
-
How do I submit form without page reload taking into consideration the php script?
So basically I have to work on this loan calculator loancalc.000webhostapp.com
I have looked at other pages on this site "how to submit form without page reload?" but this isn't completely relevant to what i'm working on. So far i've added this into the jquery part of the page...
jQuery('qis-register').on('submit', 'input', function(){ event.preventDefault(); var name = $("input#yourname").val(); var email = $("input#youremail").val(); if (name == ""){ $("input#yourname").focus; return false; } else{ } if (email == ""){ $("input#youremail").focus; return false; } });
But i'm told there is also two other scripts that I need to work with, I'm not really too experienced with php so not sure what's going on, the two php scripts I have to work with are called quick-interest-slider.php and register.php,
//qis_verify_application in register.php function qis_verify_application(&$values, &$errors) { $application = qis_get_stored_application(); $register = qis_get_stored_application_messages(); $arr = array_map('array_shift', $application); foreach ($arr as $key => $value) { if ($application[$key]['type'] == 'multi') { $d = explode(",",$application[$key]['options']); foreach ($d as $item) { $values[$key] .= $values[$key.$item]; } } if ($application[$key]['required'] == 'checked' && $register['use'.$application[$key]['section']] && (empty($values[$key]) || $values[$key] == 'Select...')) $errors[$key] = 'error'; } $filenames = array('identityproof','addressproof'); foreach($filenames as $item) { $tmp_name = $_FILES[$item]['tmp_name']; $name = $_FILES[$item]['name']; $size = $_FILES[$item]['size']; if (file_exists($tmp_name)) { if ($size > $register['attach_size']) $errors['attach'.$item] = $register['attach_error_size']; $ext = strtolower(substr(strrchr($name,'.'),1)); if (strpos($register['attach_type'],$ext) === false) $errors['attach'.$item] = $register['attach_error_type']; } } return (count($errors) == 0); } //qis_process_application in register.php function qis_process_application($values) { global $post; $content=''; $register = qis_get_stored_register ('default'); $applicationmessages = qis_get_stored_application_messages(); $settings = qis_get_stored_settings(); $auto = qis_get_stored_autoresponder(); $application = qis_get_stored_application(); $message = get_option('qis_messages'); $arr = array_map('array_shift', $application); if ($message) { $count = count($message); for($i = 0; $i <= $count; $i++) { if ($message[$i]['reference'] == $values['reference']) { $values['complete'] = 'Completed'; $message[$i] = $values; update_option('qis_messages',$message); } } } $filenames = array('identityproof','addressproof'); $attachments = array(); if ( ! function_exists( 'wp_handle_upload' ) ) { require_once( ABSPATH . 'wp-admin/includes/file.php' ); } add_filter( 'upload_dir', 'qis_upload_dir' ); $dir = (realpath(WP_CONTENT_DIR . '/uploads/qis/') ? '/uploads/qis/' : '/uploads/'); foreach($filenames as $item) { $filename = $_FILES[$item]['tmp_name']; if (file_exists($filename)) { $name = $values['reference'].'-'.$_FILES[$item]['name']; $name = trim(preg_replace('/[^A-Za-z0-9. ]/', '', $name)); $name = str_replace(' ','-',$name); $_FILES[$item]['name'] = $name; $uploadedfile = $_FILES[$item]; $upload_overrides = array( 'test_form' => false ); $movefile = wp_handle_upload( $uploadedfile, $upload_overrides ); array_push($attachments , WP_CONTENT_DIR .$dir.$name); } } remove_filter( 'upload_dir', 'qis_upload_dir' ); $content = qis_build_complete_message($values,$application,$arr,$register); qis_send_full_notification ($register,$values,$content,true,$attachments); qis_send_full_confirmation ($auto,$values,$content,$register); }
function qis_loop in quick-interest-slider.php
function qis_loop($atts) { $qppkey = get_option('qpp_key'); if (!$qppkey['authorised']) { $atts['formheader'] = $atts['loanlabel'] = $atts['termlabel'] = $atts['application'] = $atts['applynow'] = $atts['interestslider'] = $atts['intereselector']= $atts['usecurrencies'] = $atts['usefx'] = $atts['usedownpayment'] = false; if ($atts['interesttype'] == 'amortization' || $atts['interesttype'] == 'amortisation') $atts['interesttype'] = 'compound'; } global $post; // Apply Now Button if (!empty($_POST['qisapply'])) { $settings = qis_get_stored_settings(); $formvalues = $_POST; $url = $settings['applynowaction']; if ($settings['applynowquery']) $url = $url.'?amount='.$_POST['loan-amount'].'&period='.$_POST['loan-period']; echo "<p>".__('Redirecting....','quick-interest-slider')."</p><meta http-equiv='refresh' content='0;url=$url' />"; die(); // Application Form } elseif (!empty($_POST['qissubmit'])) { $formvalues = $_POST; $formerrors = array(); if (!qis_verify_form($formvalues, $formerrors)) { return qis_display($atts,$formvalues, $formerrors,null); } else { qis_process_form($formvalues); $apply = qis_get_stored_application_messages(); if ($apply['enable'] || $atts['parttwo']) return qis_display_application($formvalues,array(),'checked'); else return qis_display($atts,$formvalues, array(),'checked'); } // Part 2 Application } elseif (!empty($_POST['part2submit'])) { $formvalues = $_POST; $formerrors = array(); if (!qis_verify_application($formvalues, $formerrors)) { return qis_display_application($formvalues, $formerrors,null); } else { qis_process_application($formvalues); return qis_display_result($formvalues); } // Default Display } else { $formname = $atts['formname'] == 'alternate' ? 'alternate' : ''; $settings = qis_get_stored_settings(); $values = qis_get_stored_register($formname); $values['formname'] = $formname; $arr = explode(",",$settings['interestdropdownvalues']); $values['interestdropdown'] = $arr[0]; $digit1 = mt_rand(1,10); $digit2 = mt_rand(1,10); if( $digit2 >= $digit1 ) { $values['thesum'] = "$digit1 + $digit2"; $values['answer'] = $digit1 + $digit2; } else { $values['thesum'] = "$digit1 - $digit2"; $values['answer'] = $digit1 - $digit2; } return qis_display($atts,$values ,array(),null); } }
Do I have to edit any of the php and I also don't know what I have to write considering the php.
-
Refreshing XML information in Microsoft Access?
Versions XML & XSLT Version 1 and MS-Access365
I am using XSLT to transform some XML tables which are then imported into MS-Access. The import is exactly what I need but when I save the import steps and run them later I get the following message:
The specification failed to execute. Try re-creating the specification.
When I try to just run the import again it gives me another instance of the table (I.E. Table1 when I want the data to go into Table), and appending information doesn't work becuase I want the old data to be removed. Ideally I just want to hit Refresh and have the data updated with the XML.
I tried using the Linked Table Manager but none of the connection strings I've written are valid. Is there a solution that will allow me to refresh XML files in the same way that MS-Excel does?
-
XSLT - Copy all nodes and add extra node
I have the XML below:
<?xml version="1.0"?> <CWTPNR xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"> <CreationDate>2017-04-10T04:53:25.3070017Z</CreationDate> <Locator>JMYCOC</Locator> <FirstName>BARRY </FirstName> <LastName>TRAILL</LastName> <EmployeeID /> <PhoneNumber>61-0448793334</PhoneNumber> <TravelerType>GENERAL</TravelerType> <Email>BTRAILL@PEWTRUS2TS.ORG</Email> <ItineraryEvents> <ItineraryEvent Type="Hotel"> <StartDateTime>2017-04-26T00:00:00</StartDateTime> <EndDateTime>2017-04-28T00:00:00</EndDateTime> <StartAirport>PDX</StartAirport> <EndAirport>PDX</EndAirport> <Designator>DOWNTOWN VALUE INN</Designator> <Address>415 SW MONTGOMERY ST, PORTLAND, OR 97201</Address> <SegmentNumber>1</SegmentNumber> </ItineraryEvent> </ItineraryEvents> <CompanyID>2206</CompanyID> <FeedDate>2017-04-10T04:53:25.3070017Z</FeedDate> <TransactionID>33:c7c24acf-2ed6-4210-bf11-aafc73b032dc</TransactionID> <TransactionType>PASSED_QC</TransactionType> <GDSName>Sabre</GDSName> <ClientTop>14:178B89</ClientTop> <ClientSub>14:1D38C4</ClientSub> </CWTPNR>
I want to add
<IGNORE/>
tag inside<CWTPNR>
parent tags, here is the XSLT I tried but it doesn't work:<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0" xmlns:user="urn:my-scripts" xmlns:msxsl="urn:schemas-microsoft-com:xslt" exclude-result-prefixes="msxsl"> <xsl:variable name="hhref" select="link" /> <xsl:template match="@*|node()"> <xsl:copy> <xsl:apply-templates select="@*|node()" /> </xsl:copy> </xsl:template> <xsl:template match="CreationDate"> <xsl:copy-of select="."/> <IGNORE/> </xsl:template> <msxsl:script language="C#" implements-prefix="user"> <![CDATA[ public string Upper(string stringToModify) { return stringToModify.ToUpper(); } ]]> </msxsl:script> </xsl:stylesheet>
-
How to version a xml file so that it doesn't get overwrite error when publishing to artifactory
Trying to figure out a way to send XML files from Bitbucket to artifactory with the help of jenkins. The Xml are not built or compiled so, when tried to upload that modified xml to the artifactory, gives "Not enough permissions to overwrite artifact". Can you rename the XML with version name like ABC-version.xml automatically, everytime i do commit to bitbucket. if so what will be the process to do it?
I don't want to rename my file everytime before i do commit to bitbucket.
-
How to create a structure of html tags on php
I have to create a this html structure:
<figure class="op-interactive"> <iframe> <div> <script async="" height="" src="src" width=""></script> </div> </iframe> </figure>
and this is my code:
$media_embed = $doc->getElementsByTagName('div'); foreach ($media_embed as $media){ $scriptstag = $media->getElementsByTagName('script'); foreach ($scriptstag as $scripts) { $src= $scripts->getAttribute('src'); $newFigure = $doc->createElement('figure'); $newFigure->setAttribute('class','op-interactive'); $newiFrame = $doc->createElement('iframe'); $newFigure->appendChild($newiFrame); $newDiv = $doc->createElement('div'); $newiFrame->appendChild($newDiv); $scripts->parentNode->insertBefore($newFigure, $scripts); $newiFrame->appendChild($scripts); } } $body1 = $doc->saveHTML($doc->documentElement);
But the output is this:
<figure class="op-interactive"> <iframe> <div> </div> <script async="" height="" src="src" width=""></script> </iframe> </figure>
i dont know how to insert
script
tag betweendiv
tag, is there something missing in my code? im using this page to share my test:http://sandbox.onlinephpfunctions.com/code/00c285949a467fe44d4a5ce2ed002e6b0ef670a6could you please help me? thank you
-
Is there a way to iterate over an unordered list with sublists - no jQuery?
I want to highlight every list item in my unordered list 'g1'. The list has several sublists. I want to press 'arrow down' and 'up' to highlight the next item. I was able to iterate over the outer list, but with the sublists, my solution becomes super messy. Is there a better way than mine with pure JavaScript?
<!DOCTYPE html> <html> <head> <meta charset="utf-8" /> <title>Family Tree</title> </head> <body id='main'> <nav> <h1 id=pos></h1> </nav> <ul id='g1' class="special"> <ul id='generation2'> <li>John Williams</li> <li>Filippa Williams</li> <ul id='generation3'> <li>Juan James</li> <li>Catarina James</li> <li>Aoifa James</li> </ul> <li>Juan Williams</li> </ul> <li>Mark Williams</li> <li>Christina Johnson</li> <li>Christina Johnson</li> <li>Christina Johnson</li> <li>Juan Williams</li> <li>Juan Williams</li> <ul id='generation2'> <li>John Williams</li> <li>Filippa Williams</li> </ul> </ul> </body> </html> document.onkeydown = function (e) { switch (e.keyCode) { case 37: alert('left'); break; case 38: up() break; case 39: alert('right'); break; case 40: down(); break; } }; var pos = -1; var posSub = -1; var posSubSub = 0; var pointer; function down() { var childrensChildren; var childrensGrandchildren; var gen1 = document.getElementById('g1'); var gen1children = gen1.children; if (pos === -1) { gen1children[0].style.backgroundColor = 'yellow'; pos++; document.getElementById('pos').innerHTML = pos; return null; } if (pos == gen1children.length - 1) { gen1children[gen1children.length - 1].style.backgroundColor = 'white'; gen1children[0].style.backgroundColor = 'yellow'; pos = 0; document.getElementById('pos').innerHTML = pos; return null; } if (gen1children[pos].firstElementChild) { var childrensChildren = gen1children[pos].children; if (childrensChildren.firstChild) { childrensGrandchildren = childrensChildren[posSub].children; childrensGrandchildren[posSubSub].style.backgroundColor = 'yellow'; childrensGrandchildren[childrensGrandchildren.length - 1].style.backgroundColor = 'white'; posSubSub++; } else { if (posSub === -1) { childrensChildren[0].style.backgroundColor = 'yellow'; posSub++; return null; } if (posSub == childrensChildren.length - 1) { childrensChildren[childrensChildren.length - 1].style.backgroundColor = 'white'; childrensChildren[0].style.backgroundColor = 'yellow'; return null; } else { posSub += 1; childrensChildren[posSub - 1].style.backgroundColor = 'white'; childrensChildren[posSub].style.backgroundColor = 'yellow'; return null; } } } gen1children[pos].style.backgroundColor = 'white'; gen1children[pos + 1].style.backgroundColor = 'yellow'; pos += 1; document.getElementById('pos').innerHTML = pos; return null; } function up() { var gen1 = document.getElementById('g1'); var gen1children = gen1.children; if (pos === -1) { gen1children[0].style.backgroundColor = 'yellow'; pos++; document.getElementById('pos').innerHTML = pos; return null; } if (pos == 0) { gen1children[gen1children.length - 1].style.backgroundColor = 'yellow'; gen1children[0].style.backgroundColor = 'white'; pos = gen1children.length - 1; document.getElementById('pos').innerHTML = pos; return null; } gen1children[pos].style.backgroundColor = 'white'; gen1children[pos - 1].style.backgroundColor = 'yellow'; pos -= 1; document.getElementById('pos').innerHTML = pos; return null; }
-
addEventListener null, onclick works (onload did not work and js is in separate document)
I can use onClick in my HTML file to call upon functions created in my JavaScript file, however, attempting to use
addEventListener
does not work and I am not sure why. Error inconsole.log
says that theaddEventListner
is null.I am attempting to change the display of my web page via a click event.
I understand that
addEventListener
does not cancel out the previous event called, but even the first event called in my code does not trigger the change which is confusing.After looking this up I tried the following:
Using
window.onload = function(){}
and placing the below code within the function.document.getElementById('begin_game').addEventListener('click', beginGame);
document.getElementById('select_category').addEventListener('click', selectCategory);
Using this code independent of the
window.onload
function but theaddEventListener
still returned as null.
The
beginGame
andselectCategory
functions reference the following code in the js file:function Hide(x) { const hidden = document.getElementsByClassName(x); for (var i=0, length= hidden.length; i < length; i++) { if ( hidden[i].style.display != 'none') { hidden[i].style.display = 'none'; } } } function Display(x) { const show = document.getElementsByClassName(x); for (var i = 0, length = show.length; i < length; i++) { if (show[i].style.display != 'flex') { show[i].style.display = 'flex'; } } } //Below is how the functions are referenced function beginGame() { document.getElementById('welcome').style.display = 'flex'; Hide('start'); } function selectCategory () { Hide('welcome-content'); Display('category'); } // Where I would place the event listeners I mentioned above // document.getElementById('begin_game').addEventListener('click', beginGame); // document.getElementById('select_category').addEventListener('click', selectCategory); // When I used the window.onload function, I placed it at the bottom of the js page
Buttons from HTML file
<button type='submit' class='welcome-content' id='select_category'> Categories </button> </div> <h1 class= 'start'> Math Maniacs </h1> <button type='submit' class='start' id='begin_button'> START </button>