I don't know exactly how to say that, I'll try to express myself here.
I have this feed url :
http://v2.afilio.com.br/aff/aff_boutique_show_ads.php?boutiqueid=37930-895835¤cypos=0&display_img=1&diplay_name=1&diplay_price=1&thumbsize=80%&truncate_desc=15&numrows=1&numcols=20&colorname=000000&colorprice=E30000&bkcolor=FFFFFF&bordercolor=FFFFFF&self_target=0&
It pulls out 15 items at once, it's like a store. The problem is that it won't break the line once it reaches the full width, on the other hand, it will just add a horizontal scroll bar at the bottom.
What I need to do is, instead of displaying the items like this:
|--- WIDTH 300px ---|
01 02 03 04 05 06 07 08 09 10 11 12 13 14 15
I need to display them like this:
|--- WIDTH 300px ---|
01 02 03 04 05 06
07 08 09 10 11 12
13 14 15
Here is my code :
http://v2.afilio.com.br/aff/aff_boutique_show_ads.php?boutiqueid=37930-895843¤cypos=0&display_img=1&diplay_name=1&diplay_price=1&thumbsize=80%&truncate_desc=15&numrows=1&numcols=20&colorname=000000&colorprice=E30000&bkcolor=FFFFFF&bordercolor=FFFFFF&self_target=0&");
echo ($a);
?>
I also would like to know if it's possible to use javascript instead of php.
If you dont have access another api endpoint (eg one that produces json or xml), then you will have to parse the html to strip the unwanted cruft;
$xml = new DOMDocument();
#$xml->loadHTMLFile('http://v2.afilio.com.br/aff/aff_boutique_show_ads.php?boutiqueid=37930-895835¤cypos=0&display_img=1&diplay_name=1&diplay_price=1&thumbsize=80%&truncate_desc=15&numrows=1&numcols=20&colorname=000000&colorprice=E30000&bkcolor=FFFFFF&bordercolor=FFFFFF&self_target=0&');
$products = array();
//Loop through each <td> tag in the dom and extract inner html
foreach($xml->getElementsByTagName('td') as $p) {
$children = $p->childNodes;
$phtml = '';
foreach ($children as $child)
{
$phtml.= $p->ownerDocument->saveHTML($child);
}
echo '<div class="product">' . $phtml . '</div>';
}
Css
<style type="text/css">
.product{
width: 100px; float:left;
}
</style>
Related
I have this code below and I am trying to add html before and after a span which has no id.
I can only select it with the :contains selector.
Using this selector, how can I add my elements?
var tel = $('span:contains("+33 (0)1 02 03 04 05")');
var telText = tel.text();
var newTel = '' + telText + '';
tel.html(newTel);
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.js">
<span>phone number</span>
<span>+33 (0)1 02 03 04 05</span>
It works here, you just have to use contains on the text that is inside the span.
var tel = $('span:contains("+33 (0)1 02 03 04 05")');
var telText = tel.text();
var newTel = '' + telText + '';
tel.html(newTel);
console.log(telText)
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.js"></script>
<span>phone number</span>
<span>+33 (0)1 02 03 04 05</span>
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 6 years ago.
Improve this question
Thanks for coming and understand I am new to this. So what seems easy to some is new to me.
I did some research on how to use javascript and/or php to pull data from an .xml file. I also can pull this .xml data into a mobile app using html5 canvas ( Construct 2 )
My issue is not related to nodes per se, But then again it is.
As it is easier if the node had text like this one.
<item>Hi There</item>
instead of subnodes like the one I wish to scrape.
<item game="powerball" nextjp="$67 Million" nextdd="Wednesday, August 10, 2016" winnum="20-33-36-47-52 PB12 X3" windd="Saturday, August 6, 2016" myflv="widget_pb.flv" winnumNM="20-33-36-47-52 PB12" name="POWERBALL">
I wish to break down the node so that it reads
Game
Next Jackpot
Next drawing
Winning Numbers
Game Played Date
It would have been easy for me if I could find an xml that already had the Nodes for each instead of all them inside one node. So with that said I don't need a full detailed script demo, I just need a basic overview of how it is done to get the subnode data. Thanks Jeremy C.
In this case I've loaded the entire XML from a string. In real case, you'll need to probably pull it using ajax.
Note: the URL you added in comments from which I got this xml from doesnt have 'Allow * Origin Header" so, ajax from there will create a CORS error.
var xml = '<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"><channel><title>Florida Lottery Winning Numbers</title><link>http://www.flalottery.com</link><description>Florida Lottery winning number drawing results for FLORIDA LOTTO, MEGA MILLIONS, POWERBALL, LUCKY MONEY, FANTASY 5, Midday and Evening PICK 2, PICK3, PICK 4 and PICK 5</description><item game="powerball" nextjp="$67 Million" nextdd="Wednesday, August 10, 2016" winnum="20-33-36-47-52 PB12 X3" windd="Saturday, August 6, 2016" myflv="widget_pb.flv" winnumNM="20-33-36-47-52 PB12" name="POWERBALL"><title>POWERBALL Drawing Results</title><link>http://www.flalottery.com/powerball.do</link><description>POWERBALL winning numbers are 20-33-36-47-52 PB12 X3 for 08/06/2016 and the next estimated Jackpot is $67 Million for 08/10/2016</description><pubDate>Wed, 10 Aug 2016 22:11:46 EST</pubDate><guid>http://www.flalottery.com/powerball.do</guid></item><item game="lotto" nextjp="$12 Million" nextdd="Wednesday, August 10, 2016" winnum="1-22-27-40-42-53 X3" windd="Saturday, August 6, 2016" myflv="widget_l6.flv" name="FLORIDA LOTTO"><title>FLORIDA LOTTO Drawing Results</title><link>http://www.flalottery.com/lotto.do</link><description>FLORIDA LOTTO with Xtra winning numbers are 1-22-27-40-42-53 X3 for 08/06/2016 and the next Jackpot is $12 Million for 08/10/2016</description><pubDate>Wed, 10 Aug 2016 22:11:46 EST</pubDate><guid>http://www.flalottery.com/lotto.do</guid></item><item game="fan5" winnum="3-23-25-33-34" windd="Tuesday, August 9, 2016" myflv="widget_f5.flv" name="FANTASY 5"><title>FANTASY 5 Drawing Results</title><link>http://www.flalottery.com/fantasy5.do</link><description>FANTASY 5 winning numbers are 3-23-25-33-34 for 08/09/2016</description><pubDate>Wed, 10 Aug 2016 22:11:46 EST</pubDate><guid>http://www.flalottery.com/fantasy5.do</guid></item><item game="pick5" winnumm="6-7-9-1-9" midd="Wednesday, August 10, 2016" winnume="4-7-1-9-1" eved="Wednesday, August 10, 2016" myflvm="NA" myflve="NA" name="PICK 5"><title>PICK 5 Drawing Results</title><link>http://www.flalottery.com/pick5.do</link><description>PICK 5 winning numbers are 6-7-9-1-9 for Midday 08/10/2016 and 4-7-1-9-1 for Evening 08/10/2016</description><pubDate>Wed, 10 Aug 2016 22:11:46 EST</pubDate><guid>http://www.flalottery.com/pick5.do</guid></item><item game="pick4" winnumm="3-6-4-7" midd="Wednesday, August 10, 2016" winnume="7-1-1-7" eved="Wednesday, August 10, 2016" myflvm="widget_p4_midd.flv" myflve="widget_p4_eved.flv" name="PICK 4"><title>PICK 4 Drawing Results</title><link>http://www.flalottery.com/pick4.do</link><description>PICK 4 winning numbers are 3-6-4-7 for Midday 08/10/2016 and 7-1-1-7 for Evening 08/10/2016</description><pubDate>Wed, 10 Aug 2016 22:11:46 EST</pubDate><guid>http://www.flalottery.com/pick4.do</guid></item><item game="pick3" winnumm="3-5-0" midd="Wednesday, August 10, 2016" winnume="2-4-8" eved="Wednesday, August 10, 2016" myflvm="widget_c3_midd.flv" myflve="widget_c3_eved.flv" name="PICK 3"><title>PICK 3 Drawing Results</title><link>http://www.flalottery.com/pick3.do</link><description>PICK 3 winning numbers are 3-5-0 for Midday 08/10/2016 and 2-4-8 for Evening 08/10/2016</description><pubDate>Wed, 10 Aug 2016 22:11:46 EST</pubDate><guid>http://www.flalottery.com/pick3.do</guid></item><item game="pick2" winnumm="9-6" midd="Wednesday, August 10, 2016" winnume="7-7" eved="Wednesday, August 10, 2016" myflvm="NA" myflve="NA" name="PICK 2"><title>PICK 2 Drawing Results</title><link>http://www.flalottery.com/pick2.do</link><description>PICK 2 winning numbers are 9-6 for Midday 08/10/2016 and 7-7 for Evening 08/10/2016</description><pubDate>Wed, 10 Aug 2016 22:11:46 EST</pubDate><guid>http://www.flalottery.com/pick2.do</guid></item><item game="megamillions" nextjp="$45 Million" nextdd="Friday, August 12, 2016" winnum="12-19-20-44-66 MM1 X5" windd="Tuesday, August 9, 2016" name="MEGA MILLIONS"><title>MEGA MILLIONS Drawing Results</title><link>http://www.flalottery.com/megaMillions.do</link><description>MEGA MILLIONS winning numbers are 12-19-20-44-66 MM1 X5 for 08/09/2016 and the next estimated Jackpot is $45 Million for 08/12/2016</description><pubDate>Wed, 10 Aug 2016 22:11:46 EST</pubDate><guid>http://www.flalottery.com/megaMillions.do</guid></item><item game="lucky" nextjp="$700,000" nextdd="Friday, August 12, 2016" winnum="1-11-27-39 LB3" windd="Tuesday, August 9, 2016" myflv="widget_lucky.flv" name="LUCKY MONEY"><title>LUCKY MONEY Drawing Results</title><link>http://www.flalottery.com/luckyMoney.do</link><description>LUCKY MONEY winning numbers are 1-11-27-39 LB3 for 08/09/2016 and the next Jackpot is $700,000 for 08/12/2016</description><pubDate>Wed, 10 Aug 2016 22:11:46 EST</pubDate><guid>http://www.flalottery.com/luckyMoney.do</guid></item></channel></rss>';
var xmlDoc = $.parseXML(xml),
$xml = $(xmlDoc),
$data = $xml.find("item");
var res = "";
$data.each(function() {
var str = "<tr>";
str += "<td>" + ($(this).attr('game')) + "</td>";
str += "<td>" + ($(this).attr('nextjp')) + "</td>";
str += "<td>" + ($(this).attr('nextdd')) + "</td>";
str += "<td>" + ($(this).attr('winnum')) + "</td>";
str += "<td>" + ($(this).attr('windd')) + "</td>";
str += "</tr>";
res += str;
});
$("#output").append(res);
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<table id="output" border="1">
<tr>
<th>Game</th>
<th>Next Jackpot</th>
<th>Next drawing</th>
<th>Winning Numbers</th>
<th>Game Played Date</th>
</tr>
</table>
This question already has an answer here:
I want to split a string and want to put in the dropdown list in html, javascript [closed]
(1 answer)
Closed 8 years ago.
strPropertyEvents=20 Aug 2014-New Activity 1, 21 Aug 2014-gfdbfjdb ,21 Aug 2014-anubhav, 24 ug 2014-hjdf
Basically In strPropertyEvents it is stored in the form of string but I want to split this string in such a manner that where there is a comma , it splits down there and the output is in a dropdown list as
<script type="text/javascript">
$('#hiddenActivityDate').val('#strPropertyEvents');
alert($('#hiddenActivityDate').val());
var strList = hiddenActivityDate.split(',');
console.log(strList);
$.each(strList,function(index,val){
$("#ProgramList").append('<option>'+val+'</option>');
});
</script>
But the code is not working. Could you please help me out what is the mistake either in fiddle or anywhere.
I don't find the definition of hiddenActivityDate
<script type="text/javascript">
$('#hiddenActivityDate').val('#strPropertyEvents');
var hiddenActivityDate = $('#hiddenActivityDate').val();
var strList = hiddenActivityDate.split(',');
console.log(strList);
$.each(strList,function(index,val){
$("#ProgramList").append('<option>'+val+'</option>');
});
</script>
I'm not quite sure where you get the string from, but I've added a working example where the string is declared at the top, as well as in a hidden input field.
<script type="text/javascript">
$(document).ready(function(){
var strPropertyEvents="20 Aug 2014-New Activity 1, 21 Aug 2014-gfdbfjdb ,21 Aug 2014-anubhav, 24 ug 2014-hjdf";
$('#hiddenActivityDate').val(strPropertyEvents);
var strList = strPropertyEvents.split(',');
console.log(strList);
$.each(strList,function(index,val){
$("#ProgramList").append('<option>'+val+'</option>');
});
});
</script>
<input id="hiddenActivityDate" type="hidden" />
<select id="ProgramList"></select>
fiddle
For some reason I am getting an error in FireFox only:
Typeerror: document.forms.myCity.optionname is undefined
The script works in all the other browsers:
function WriteCookie()
{
document.cookie = "city" + '=; expires=Thu, 01 Jan 1970 00:00:01 GMT;';
cookievalue = document.forms['myCity'].optionname.value + ";";
document.cookie='city='+cookievalue +'; expires=Fri, 3 Aug 2021 20:47:11 UTC; path=/';
window.location.href = "http://mywebsite.com";
}
This script is in the header and is executed by this form:
<form name="myCity" action="http://mywebsite.com/" method="POST">
<?php
function get_terms_dropdown($taxonomies, $args){
$myterms = get_terms($taxonomies, $args);
$optionname = "optionname";
$emptyvalue = "";
$output ="<select name='". $optionname ."'><option selected='". $selected . "' value='" . $emptyvalue . "'>Select a City</option>'";
foreach($myterms as $term){
$term_taxonomy=$term->pa_city; //CHANGE ME
$term_slug=$term->slug;
$term_name =$term->name;
$link = $term_slug;
$output .="<option name='".$link."' value='".$link."'>".$term_name."</option>";
}
$output .="</select>";
return $output;
}
$taxonomies = array('pa_city');
$args = array('order'=>'ASC','hide_empty'=>true);
echo get_terms_dropdown($taxonomies, $args);
?>
<input type="submit" value="click" name="submit" onclick="WriteCookie()">
</form>
The error is only in FireFox, any ideas?
Your error is this:
Typeerror: document.forms.myCity.optionname is undefined
I believe the issue is in this element:
<form name="myCity" action="http://mywebsite.com/" method="POST">
It looks like forms use the id selector instead of the name selector. I ran into this issue before, and I solved it by placing both id and name into the <form> element. The only explicit online reference I can find to this is here from the MSN XHTML Standards page:
The name attribute on the form element is not allowed in XHTML 1.1
guidelines.
I also found a discussion thread here on XHML 1.1 strict standards & forms that makes reference to it as well:
The W3 says the name attribute is deprecated a deprecated part of HTML
4.0 and only the ID tag fits the new XHTML 1.1 standards.
And then I found this official W3 reference that nails the issue on the head; emphasis is mine:
name = cdata [CI]
This attribute names the element so that it may be
referred to from style sheets or scripts. Note. This attribute has
been included for backwards compatibility. Applications should use the
id attribute to identify elements.
So just add an id attribute to that element like this:
<form name="myCity" id="myCity" action="http://mywebsite.com/" method="POST">
You want to have both name and id in there to cover all bases on different browsers and their implementation of XHTML 1.1 standards.
But if somehow that still does not work, just do this instead in your JavaScript on top of the id change:
function WriteCookie()
{
document.cookie = "city" + '=; expires=Thu, 01 Jan 1970 00:00:01 GMT;';
cookievalue = document.getElementById("myCity").optionname.value + ";";
document.cookie='city='+cookievalue +'; expires=Fri, 3 Aug 2021 20:47:11 UTC; path=/';
window.location.href = "http://mywebsite.com";
}
I changed the line that read like this:
cookievalue = document.forms['myCity'].optionname.value + ";";
To be this:
cookievalue = document.getElementById("myCity").optionname.value + ";";
Iep, i have a problem, its the first time that im working with cookies and i was trying to save them.
The question is that only the 2 first values are saved, in this case "nombre" and "tuValor". If i do "alert(document.cookie)" the other values dont apear.
<script type="text/javascript">
function guardar() {
Nombre = "Empire";
tuValor = "F"+food;
tuValor2 = "w"+wood;
caduca = "31 Dec 2020 23:59:59 GMT";
document.cookie = Nombre+"="+tuValor+tuValor2+"expire= "+caduca ;
}
</script>
You forgot the semicolon before expire.
It goes like this:
document.cookie="my_cookie=empireWh4t3v3r;expires=Thu, 23 Apr 2020 15:37:15 GMT;"