Jump to content

StefanRSA

Members
  • Posts

    277
  • Joined

  • Last visited

Everything posted by StefanRSA

  1. Cool, I tried to use this formula given on php.net: function strip_word_html($text, $allowed_tags = '') { mb_regex_encoding('UTF-8'); //replace MS special characters first $search = array('/‘/u', '/’/u', '/“/u', '/”/u', '/—/u'); $replace = array('\'', '\'', '"', '"', '-'); $text = preg_replace($search, $replace, $text); //make sure _all_ html entities are converted to the plain ascii equivalents - it appears //in some MS headers, some html entities are encoded and some aren't $text = html_entity_decode($text, ENT_QUOTES, 'UTF-8'); //try to strip out any C style comments first, since these, embedded in html comments, seem to //prevent strip_tags from removing html comments (MS Word introduced combination) if(mb_stripos($text, '/*') !== FALSE){ $text = mb_eregi_replace('#/\*.*?\*/#s', '', $text, 'm'); } //introduce a space into any arithmetic expressions that could be caught by strip_tags so that they won't be //'<1' becomes '< 1'(note: somewhat application specific) $text = preg_replace(array('/<([0-9]+)/'), array('< $1'), $text); $text = strip_tags($text, $allowed_tags); //eliminate extraneous whitespace from start and end of line, or anywhere there are two or more spaces, convert it to one $text = preg_replace(array('/^\s\s+/', '/\s\s+$/', '/\s\s+/u'), array('', '', ' '), $text); //strip out inline css and simplify style tags $search = array('#<(strong|b)[^>]*>(.*?)</(strong|b)>#isu', '#<(em|i)[^>]*>(.*?)</(em|i)>#isu', '#<u[^>]*>(.*?)</u>#isu'); $replace = array('<b>$2</b>', '<i>$2</i>', '<u>$1</u>'); $text = preg_replace($search, $replace, $text); //on some of the ?newer MS Word exports, where you get conditionals of the form 'if gte mso 9', etc., it appears //that whatever is in one of the html comments prevents strip_tags from eradicating the html comment that contains //some MS Style Definitions - this last bit gets rid of any leftover comments */ $num_matches = preg_match_all("/\<!--/u", $text, $matches); if($num_matches){ $text = preg_replace('/\<!--(.)*--\>/isu', '', $text); } return $text; } I have two issues... 1. How light is this formula if I wanna parse an XML file of 2Gb (estimate 400 000 entries)... Will this have a bad impact on server load? 2. This also did not solve my problem with the "£;" issue that is still left by doing the folowing....: $fullt=strip_word_html($texta);/// $fullt=str_replace('£;',"£",$fullt); Will this then be safe to directly insert into a Db field? Thanks for all your help!!!
  2. Thanks for the reply. How would i replace line breaks with proper validated line breaks? When using pure strip_tags it still leaves me with non text caracters like: ’ for ' – for - £; - for £
  3. I am parsing an XML file and importing the data to Mysql Db. One of the nodes is text but contains random URL Links, sometimes css and html and sometimes multiple <br>, <lu>, <li> x2, x3 x4 I want to clean the text to be imported to be without URL links, css & html, but want to keep it tidy to be displayed as regular text on a webpage with regular spacing... I also need to get rid of untidy extra spaces and so more... The code I am using are not so fresh and give me broken text. What will be a more acceptable way than my following code? $fullt=str_replace("\n","",$texta); $fullt = preg_replace("/[\r\n]+/", "\n", $fullt); $fullt=trim($fullt); $fullt = preg_replace('|https?://www\.[a-z\.0-9]+|i', '', $fullt); $fullt = preg_replace('|www\.[a-z\.0-9]+|i', '', $fullt); $fullt=str_replace('">',"",$fullt); $fullt=str_replace('<"',"",$fullt); $fullt=preg_replace('/\s*$^\s*/m', "\n", $fullt); $fullt=str_replace('<BR/>',"<br>",$fullt); $fullt=str_replace('<br><br><br>',"<br>",$fullt); $fullt=str_replace('<br> <br>',"<br>",$fullt); $fullt=str_replace('&nbsp',"",$fullt); $fullt=str_replace('<br><br>',"<br>",$fullt); $fullt=str_replace('a href',"",$fullt); $fullt=str_replace('"',"",$fullt); $fullt=str_replace(';',"",$fullt); $fullt=str_replace(';',"",$fullt); $fullt=str_replace('^',"",$fullt); $qs='?'; $fullt = preg_replace( '@^(<br\\b[^>]*/'.$qs.'>)+@i', '', $fullt); //// Text ready $fullt=mysql_real_escape_string($fullt);
  4. Why not doing a simple Lookup first to see if the userid exists and then do the Update or insert?
  5. I need to import a 2Gb XML file into Mysql Db. The XML is built like the following sample <?xml version="1.0" encoding="UTF-8"?> <Properties> <Property> <ID></ID> <price></price> <price></price> <price></price> <price></price> <image id='1'> </image> <image id='2'> </image> <image id='3'> </image> </Property> <Property> ....... </Property> <Properties> I am now trying to get the id, the value of the 4th price node as well as the two first image node values... I am stuck... Please help. My script sofar: <? $reader = new XMLReader(); $reader->open($url); while($reader->read()){ if($reader->nodeType == XMLReader::ELEMENT) $nodeName = $reader->name; if($reader->nodeType == XMLReader::TEXT || $reader->nodeType == XMLReader::CDATA) { if ($nodeName == 'ID'){ $id = $reader->value; echo $id; } if ($nodeName == 'Price'){ $price = $reader->value; echo $price['4']; } if ($nodeName == 'Image'){ if($reader->getAttribute("id") == '1') { $image1= $reader->value; }else if($reader->getAttribute("id") == '2'){ $image2= $reader->value; } } } } ?>
  6. I am trying the XMLReader as follow: (This is not working... Any help?) #!/usr/bin/php –q <? error_reporting(E_ALL); ini_set('display_errors', '1'); $url='http://xxxxxxx.xxx'; $reader = new XMLReader(); $reader->open($url); while($reader->read()){ if($reader->nodeType == XMLReader::ELEMENT) $nodeName = $reader->name; if($reader->nodeType == XMLReader::TEXT || $reader->nodeType == XMLReader::CDATA) { if ($nodeName == 'ID'){ $adnr = $reader->value; echo $adnr.'<br>'; } if ($nodeName == 'Country'){ $country= $reader->value; } if ($nodeName == 'Location1'){ $province = $reader->value; } if ($nodeName == 'Location2'){ $region = $reader->value; } if ($nodeName == 'Location3'){ $town = $reader->value; } if ($nodeName == 'Price'){ $price =$reader->getAttribute('4'); echo 'Price='.$price.'/n/n'; } if ($nodeName == 'Beds'){ $bedrooms = $reader->value; } if ($nodeName == 'Ref'){ $ref = $reader->value; } if ($nodeName == 'Name'){ $bname = $reader->value; } if ($nodeName == 'Sector'){ $sector = $reader->value; $sector=trim(preg_replace('/\s+/', ' ', $sector)); } if ($nodeName == 'Type'){ $type = $reader->value; $hometype = trim($type.' '.$sector); $hometype=trim(preg_replace('/\s+/', ' ', $hometype)); } if ($nodeName == 'Key_selling_points'){ $keyfield = $reader->value; } if ($nodeName == 'Baths'){ $bathrooms = $reader->value; } if ($nodeName == 'Full_Desc'){ $fullt = $reader->value; } if ($nodeName == 'image'){ $pic1 = $reader->getAttribute('1')->value; } if ($nodeName == 'image'){ $pic2 = $reader->getAttribute('2')->value; } if ($nodeName == 'image'){ $pic3 = $reader->getAttribute('3')->value; } if ($nodeName == 'image'){ $pic4 = $reader->getAttribute('4')->value; } if ($nodeName == 'image'){ $pic5 = $reader->getAttribute('5')->value; } if ($nodeName == 'image'){ $pic6 = $reader->getAttribute('6')->value; } ///////////////////////////////////////// } $count='0'; if($reader->nodeType == XMLReader::END_ELEMENT && $reader->name == 'Property') { $count++; } } $reader->close(); echo $count; ?>
  7. I need to import a large XML file into my DB (2Gb) I tried to use DOMDocument and it failed cause of size and read up and understand that I should rather use XMLReader. Google search do not help much to give me an indication what I should different to read the document with XMLReader... Can anybody please help me to either point me in the right direction to fix this document I created or even help me to rewrite the parser... I just cannot get my head arounf this problem... My DOMDocument is as follow: #!/usr/bin/php –q <? error_reporting(E_ALL); ini_set('display_errors', '1'); $l = mysql_connect ( XXXXX); $total='0'; $xml = "http://xxxxxxxxxxxxxxxxxxxx"; $doc = new DOMDocument(); $doc->load( $xml); ## lets read the code block $records = $doc->getElementsByTagName( "Property" ); foreach( $records as $result ) { $adnr = $result->getElementsByTagName( "ID" ); // adnr $adnr = $adnr->item(0)->nodeValue; $town = $town->getElementsByTagName( "town" ); // town $town = $town->item(0)->nodeValue; //////////////////////////////////////////////////////////////////////////////// Add Pics $pic1= $result->getElementsByTagName( "image" ); $pic1 = $pic1->item('1')->nodeValue; $pic2= $result->getElementsByTagName( "image" ); $pic2 = $pic2->item('2')->nodeValue; $pic3= $result->getElementsByTagName( "image" ); $pic3 = $pic3->item('3')->nodeValue; } ?>
  8. //$name='newpicfile'; $url=$imgurl; // create the context set_time_limit(-1); $img = file_get_contents($url); //////// GET IMAGE NAME $url_arr = explode ('/', $url); $ct = count($url_arr); $name = $url_arr[$ct-1]; $name_div = explode('.', $name); $ct_dot = count($name_div); $img_type = $name_div[$ct_dot -1]; $name=$adnr.'_'.$inr.'_'.$name; /////// GET IMAGE NAME END $im = imagecreatefromstring($img); $width = imagesx($im); $height = imagesy($im); $newwidth = '400'; $newheight = '240'; $thumb = imagecreatetruecolor($newwidth, $newheight); imagecopyresized($thumb, $im, 0, 0, 0, 0, $newwidth, $newheight, $width, $height); imagejpeg($thumb,'../ad_images/'.$name); //save image as jpg //echo '<img src="../ad_images/'.$name.'"> '; $newwidth1 = '130'; $newheight1 = '75'; $thumb1 = imagecreatetruecolor($newwidth1, $newheight1); imagecopyresized($thumb1, $im, 0, 0, 0, 0, $newwidth1, $newheight1, $width, $height); imagejpeg($thumb1,'../ad_images/130/'.$name); //save image as jpg //echo '<img src="../ad_images/130/'.$name.'"> '; $newwidth2 = '65'; $newheight2 = '37'; $thumb2 = imagecreatetruecolor($newwidth2, $newheight2); imagecopyresized($thumb2, $im, 0, 0, 0, 0, $newwidth2, $newheight2, $width, $height); imagejpeg($thumb2,'../ad_images/65/'.$name); //save image as jpg echo '<img src="../ad_images/65/'.$name.'"> <br>'; $dbname=$name; $pquery = "INSERT INTO *****"; mysql_query($pquery); imagedestroy($thumb); imagedestroy($thumb1); imagedestroy($thumb2); imagedestroy($im); Am sure this will help somewhere, someone else... ;-) Thanks for the reply mac
  9. Hi, I am getting an image URL from an xml feed. I am trying to copy the image from the URL in the XML Feed, then rename & resize it. Its only giving me a black resized block for each image resize... This is driving me nuts. Please look at my script and tell me where am I going wrong? set_time_limit(-1); $imgurl='http://path/to/img_main.jpg'; $pic=$imgurl; $img = $pic; //////// GET IMAGE NAME $url_arr = explode ('/', $pic); $ct = count($url_arr); $name = $url_arr[$ct-1]; $name_div = explode('.', $name); $ct_dot = count($name_div); $img_type = $name_div[$ct_dot -1]; /////// GET IMAGE NAME END $name= str_replace(' ', '_', $name); $im = imagecreatefromjpeg($img); $width = imagesx($im); $height = imagesy($im); $newwidth = '400'; $newheight = '240'; $thumb = imagecreatetruecolor($newwidth, $newheight); imagecopyresized($thumb, $im, 0, 0, 0, 0, $newwidth, $newheight, $width, $height); imagejpeg($thumb,'../ad_images/'.$name); //save image as jpg echo '<img src="../ad_images/'.$name.'"> '; $newwidth1 = '130'; $newheight1 = '98'; $thumb1 = imagecreatetruecolor($newwidth1, $newheight1); imagecopyresized($thumb1, $im, 0, 0, 0, 0, $newwidth1, $newheight1, $width, $height); imagejpeg($thumb1,'../ad_images/130/'.$name); //save image as jpg echo '<img src="../ad_images/130/'.$name.'"> '; $newwidth2 = '65'; $newheight2 = '49'; $thumb2 = imagecreatetruecolor($newwidth2, $newheight2); imagecopyresized($thumb2, $im, 0, 0, 0, 0, $newwidth2, $newheight2, $width, $height); imagejpeg($thumb2,'../ad_images/65/'.$name); //save image as jpg echo '<img src="../ad_images/65/'.$name.'"> <br>'; $dbname=$name; imagedestroy($thumb); imagedestroy($thumb1); imagedestroy($thumb2); imagedestroy($im);
  10. Thanks Lemmin... Was never thinking to do it straight on the MySql query. Will test it, thanks
  11. I have an action that sets current time in the DB. I want to run a cronjob on a 5min interval to check for documents that is not set 5min ahead of time when cron runs, but also not in the past of when the cron runs and then perform a certain action.... Id tried it with the following code but its not working... Any ideas? $t=date("H:i:s", time()); echo $t.'<br>'; $currentTime = strtotime($t); $futureTime = $currentTime+(60*5); $plus5min = date("H:i:s", $futureTime); echo $plus5min; $inbetween = $currentTime+(60*3); $plus3min = date("H:i:s", $inbetween); echo '<br><br>'.$plus3min; if (($plus3min<=$plus5min) && ($plus3min>=$currentTime)){ echo '<br><br>inbetween'; }else{ echo '<br><br>Not Now'; }
  12. Thanks for the help... My join order was wrong...
  13. Sorry Barand, Yes, the "sct" column is indexed.
  14. timcadieux - I just tried version one and did not really see an improvement... Will try V2 Barand - Yes, all related columns are indexed...
  15. I have a DB with 400 000+ entries and am trying to split it into 10 entries per page... My usual paging for smaller DB rows are working fine with no loading issues. Just with the large table (with joins) it bacomes a very long page load. I am not sure what should be done to improve page load.... The script I have for paging works as follow: $query2 = mysql_query("SELECT COUNT( * ) FROM table_in WHERE table_in.scat='$blcid' $wprov $wtown"); list($nrResults) = mysql_fetch_row($query2); //$nrResults=mysql_num_rows($result2); IF (($nrResults%$limit)<>0) { $pmax=floor($nrResults/$limit)+1; // Divide to total result by the number of rows needed per page // to display per page($limit) and create a Max page } ELSE { $pmax=floor($nrResults/$limit); } $pagenumber=(($pages-1)*$limit); $query= "SELECT field, field, field, field FROM table_in JOIN s_tow ON s_tow.tId=table_in.tow JOIN s_reg ON s_reg.rId=table_in.ar JOIN s_pro ON s_pro.pId=table_in.pro JOIN bt ON bt.id=table_in.lid WHERE table_in.sct='$blcid' $wprov $wtown GROUP BY table.lid ORDER BY date $nav limit $pagenumber, $limit"; $allads=mysql_query($query) or die(mysql_error()); This works fine if I have up to 500 rows.... But cause havoc with 400 000 rows.... What should I do?
  16. I have a form in an iframe in a parent form. The iframe has a multiple select box.... I am trying to transfer the Iframe fields to the parent form on parent form submit. All works fine for text fields, but the multiple select field do not $_Post the multiple selected values, and only the first selected option in the form.... What am I doing wrong? function fillValues(form){ var iElements=document.getElementById('iframe_id').contentWindow.document.forms['iframe_name'].elements, e, i=0; while(e=iElements[i++]){ form[e.name].value=e.value; } } This only transfer the first selected option in the multiple option field. Any help? The Parent Form: <head> <script type="text/javascript"> function fillValues(form){ var iElements=document.getElementById('iframe_id').contentWindow.document.forms['iframe_name'].elements, e, i=0; while(e=iElements[i++]){ form[e.name].value=e.value; } } </script> </head> <body> <? print "<pre>"; print_r($_POST); print "</pre>"; if($_POST){ $workStyle = $_POST['multiselect']; var_dump($workStyle); // Setting up a blank variable to be used in the coming loop. $allStyles = ""; // For every checkbox value sent to the form. foreach ($workStyle as $style) { // Append the string with the current array element, and then add a comma and a space at the end. $allStyles .= $style . ", "; } $allStyles = substr($allStyles, 0, -2); echo '<br>The List: '.$allStyles; } ?> <form action="<?=$root?>/member/bl_select_f.php" method="post" onsubmit="return fillValues(this)"> <input type="text" name="MainFfield" value="MainForm"> <input type="hidden" name="banner1" value=""> <input type="hidden" name="banner_name_2" value=""> <input type="hidden" name="multiselect[]" value=""> <iframe name="theselect" id="iframe_id" src="<?=$root?>/member/test1.php" height="550" width="943"> </iframe> <center>TEST<br> <input type="submit" name="blistin" id="blistin" value="Submit"> <br> TEST</center> </form> </body> The Iframe: <form name='iframe_name' id='iframe_id' method='post' action=''> <input type="text" name="banner1" value="IFRAME BOOM 1"> <input type="text" name="banner_name_2" value="IFRAME BOOM 2"> <select id="multiselect_groups" name="multiselect[]" class="multiselect" multiple="multiple"> <option value="Yes">Yes</option> <option value="No">No</option> <option value="Maybe">Maybe</option> </select> </form>
  17. Lingo, I have a complete working script in my previous post. Am sure it will help. http://forums.phpfreaks.com/topic/270366-javascript-calculation-help-needed-onselect/
  18. Hi Xaotique. In fact no.... I tried it today.... No luck... Not IE8 nor IE9 What does work is the following... (Think Admin must make it a Sticky!) Add this to the top of the script: if (!document.getElementsByClassName) { document.getElementsByClassName = function (cn) { var rx = new RegExp("(?:^|\\s)" + cn+ "(?:$|\\s)"); var allT = document.getElementsByTagName("*"), allCN = [],ac="", i = 0, a; while (a = allT[i=i+1]) { ac=a.className; if ( ac && ac.indexOf(cn) !==-1) { if(ac===cn){ allCN[allCN.length] = a; continue; } rx.test(ac) ? (allCN[allCN.length] = a) : 0; } } return allCN; } } Thanks for your reply!
  19. Hi Xaotique Wonder if you can help me here... Regarding the script I worked on... I now get an error in IE stating the following: SCRIPT438: Object doesn't support property or method 'getElementsByClassName' What is the best solution regarding this? Everything works fine in Safari, FF & Chrome... Just IE is the usual pain... Please help urgently
  20. Also, my code now works lekker (Very Nice).... Two things.... I am still not sure about the discounts I spoke about... And why does .toFixed(2) not work in the following: (I get the value from a span... Might that be the reason?) var nb = document.getElementById('b').value; window.document.getElementById("nb").innerHTML = + ((nb * weeks).toFixed(2)); Full code now looks as follow: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> <head> <title>Xaotique</title> <meta http-equiv="content-type" content="text/html;charset=utf-8" /> <script type="text/javascript"> function Calculate() { var tag = window.document.getElementsByClassName("hsnb"), total = 0; for (var i in tag) { total += tag[i].checked && !isNaN(Number(tag[i].value)) ? Number(tag[i].value) : 0; } var discount = { 1: 0, 2: 10, 3: 12.5, 4: 15 }; var tag = window.document.getElementsByClassName("weeks"); for (var i in tag) { total *= tag[i].checked && !isNaN(Number(tag[i].value)) ? Number(tag[i].value) : 1; } window.document.getElementById("outputDiv").value = + total.toFixed(2); var week = window.document.getElementsByClassName("weeks"), weeks = 0; for (var i in week) { weeks += tag[i].checked && !isNaN(Number(tag[i].value)) ? Number(tag[i].value) : 0; } window.document.getElementById("result").innerHTML = + (7 * weeks); window.document.getElementById("result_top").innerHTML = + (7 * weeks); window.document.getElementById("dayfield").value = + (7 * weeks); var nu = document.getElementById('u').value; window.document.getElementById("nu").innerHTML = + ((nu * weeks).toFixed(2)); var nh = document.getElementById('h').value; window.document.getElementById("nh").innerHTML = + ((nh * weeks).toFixed(2)); var ns = document.getElementById('s').value; window.document.getElementById("ns").innerHTML = + ((ns * weeks).toFixed(2)); var nn = document.getElementById('n').value; window.document.getElementById("nn").innerHTML = + ((nn * weeks).toFixed(2)); var nb = document.getElementById('b').value; window.document.getElementById("nb").innerHTML = + ((nb * weeks).toFixed(2)); } </script> </head> <body> (<span id="result_top">7</span> Days) <b>Weeks:</b> <input onclick="Calculate()" class="weeks" type="radio" name="weeks" value="1" checked="Checked"> 1 Week <input onclick="Calculate()" class="weeks" type="radio" name="weeks" value="2"> 2 Weeks <input onclick="Calculate()" class="weeks" type="radio" name="weeks" value="3"> 3 Weeks <input onclick="Calculate()" class="weeks" type="radio" name="weeks" value="4"> 4 Weeks <br /><br /> <input onclick="Calculate()" class="hsnb" type="checkbox" name="u" id="u" value="15"> $ <span id="nu">30</span><br> <input onclick="Calculate()" class="hsnb" type="checkbox" name="h" id="h" value="30"> $ <span id="nh">30</span><br> <input onclick="Calculate()" class="hsnb" type="checkbox" name="s" id="s" value="50"> $ <span id="ns">50</span><br> <input onclick="Calculate()" class="hsnb" type="checkbox" name="n" id="n" value="80"> $ <span id="nn">80</span><br> <input onclick="Calculate()" class="hsnb" type="checkbox" name="b" id="b" value="100"> $ <span id="nb">100</span><br> Total: R <input type="text" name="total" value="0.00" readonly="readonly" id="outputDiv"> (<span id="result">7</span> Days) <br> <input type="hidden" name="days" value="7" id="dayfield"> </body> </html>
  21. I got the totals per week to display depending on the week selected... Almost gave up! Now.... I used the sample you gave, but not sure where to put it or how to use it in the current forlmula. Please have a look and tell me what I am doing wrong? var discount = { 1: 0, 2: 10, 3: 12.5, 4: 15 }; var tag = window.document.getElementsByClassName("weeks"); for (var i in tag) { total *= tag[i].checked && !isNaN(Number(tag[i].value)) ? Number(tag[i].value) : 1; } window.document.getElementById("outputDiv").value = + total - (total * discount[weeks] / 100).toFixed(2); I only get NaN output in the field. Thanks
  22. Xaotique, I am going to skip the last idea of updating the totals for display as I just cannot get my head around it... Tried a few ways but my head hurts of all the banging against the wall... What I like to know otherwise... How to go about if I want to give a discount for more than one week... 1 Week, full price, 2 Weeks 10% discount 3 weeks 12.5% discount and 4 Weeks 15% discount...
  23. Uhm... Not sure why... But this is not working: var price = window.document.getElementsByClassName("hsnb"), total = 0; for (var i in price) { tprice += !isNaN(Number(price[i].value)) ? Number(price[i].value) : 0; } window.document.getElementsByClassName("nprice")[0].innerHTML = (nprice * weeks); window.document.getElementsByClassName("nprice")[1].innerHTML = (nprice * weeks); window.document.getElementsByClassName("nprice")[2].innerHTML = (nprice * weeks); window.document.getElementsByClassName("nprice")[3].innerHTML = (nprice * weeks); window.document.getElementsByClassName("nprice")[4].innerHTML = (nprice * weeks);
  24. Thanks Xaotique, I might be a bit confused here... Why does this not work? I have added this and put the price onscreen in a div: var price = window.document.getElementsByClassName("hsnb"), total = 0; for (var i in price) { tprice += !isNaN(Number(price[i].value)) ? Number(price[i].value) : 0; } window.document.getElementsByClassName("nprice").innerHTML = + (tprice * weeks); <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> <head> <title>Xaotique</title> <meta http-equiv="content-type" content="text/html;charset=utf-8" /> <script type="text/javascript"> function Calculate() { var tag = window.document.getElementsByClassName("hsnb"), total = 0; for (var i in tag) { total += tag[i].checked && !isNaN(Number(tag[i].value)) ? Number(tag[i].value) : 0; } var tag = window.document.getElementsByClassName("weeks"); for (var i in tag) { total *= tag[i].checked && !isNaN(Number(tag[i].value)) ? Number(tag[i].value) : 1; } window.document.getElementById("outputDiv").value = '' + total.toFixed(2); var week = window.document.getElementsByClassName("weeks"), weeks = 0; for (var i in week) { weeks += tag[i].checked && !isNaN(Number(tag[i].value)) ? Number(tag[i].value) : 0; } window.document.getElementById("result").innerHTML = + (7 * weeks); window.document.getElementById("result_top").innerHTML = + (7 * weeks); window.document.getElementById("dayfield").value = + (7 * weeks); var price = window.document.getElementsByClassName("hsnb"), total = 0; for (var i in price) { tprice += !isNaN(Number(price[i].value)) ? Number(price[i].value) : 0; } window.document.getElementsByClassName("nprice").innerHTML = + (tprice * weeks); } </script> </head> <body> <b>Weeks:</b> <input onclick="Calculate()" class="weeks" type="radio" name="weeks" value="1" checked="Checked"> 1 Week <input onclick="Calculate()" class="weeks" type="radio" name="weeks" value="2"> 2 Weeks <input onclick="Calculate()" class="weeks" type="radio" name="weeks" value="3"> 3 Weeks <input onclick="Calculate()" class="weeks" type="radio" name="weeks" value="4"> 4 Weeks <br /><br /> <input onclick="Calculate()" class="hsnb" type="checkbox" name="h" id="h" value="30.00"> $ <div class="nprice" style="display:inline;">30</div><br> <input onclick="Calculate()" class="hsnb" type="checkbox" name="s" id="s" value="50"> $ <div class="nprice" style="display:inline;">50</div><br> <input onclick="Calculate()" class="hsnb" type="checkbox" name="n" id="n" value="80"> $ <div class="nprice" style="display:inline;">80</div><br> <input onclick="Calculate()" class="hsnb" type="checkbox" name="b" id="b" value="100"> $ <div class="nprice" style="display:inline;">100</div><br> Total: R <input type="text" name="total" value="0.00" readonly="readonly" id="outputDiv"> (<span id="result">7</span> Days) <br> <input type="hidden" name="total" value="7" id="dayfield"> </body> </html>
  25. Ah... Spanner in the works! I display the price value next to each checkbox.... How do I then go about (I understand its got to be in a div with an id) to change those prices then also as per display depending on the week selection? I dont need to change the value of the fields as I will do it in script after post.... I am sure changing the values of each field will just restart my nightmare! Thanks
×
×
  • 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.