Jump to content

Psycho

Moderators
  • Posts

    12,159
  • Joined

  • Last visited

  • Days Won

    130

Everything posted by Psycho

  1. Well, as stated you cannot do it with cleint-side javascript. And, to do server-side javascript would require a webserver that supports it. That is a much more limited environment than one that supports PHP or ASP.
  2. Well, you *can* run JavaScript server-side, but that's not very common from my experience. But, if you did do that, then you can connect to a database (not sure about MySQL): http://ajaxian.com/archives/server-side-javascript-databases-access But, it would take a lot more effort to do it and there are much better languages for working with a database (such as PHP). If you are looking for a way to add/retrieve information from the client-side, then you should be looking into AJAX.
  3. I've never tried it, but I doubt that you can inject JavaScript into a page using innerHTML and expect it to work. But there are ways to dynamically add javascript to a page. Here is one possibility: First, on the main page create a script tag as follows: <script type="text/javascript" id="ajaxJS"></script> You can then dynamically add javascript using somethign like this: document.getElementById('ajaxJS').src = 'somefile.js'
  4. Make your life easier and create your query as a variable so you echo it to the page when an error occurs: <?php $title = "Thomisback"; $query = "INSERT INTO `cscart_product_descriptions` (`product_id`, `lang_code`, `product`, `shortname`, `short_description`, `full_description`, `meta_keywords`, `meta_description`, `search_words`, `page_title`) VALUES ($productid, 'EN', '$title', '', '', '', '$title', '$title', '$title', '$title'), ($productid, 'NL', '$title', '', '', '', '$title', '$title', $title'', '')"; mysql_query($query) or die ("Query:<br />$query<br />Error:<br />".mysql_error()); ?> You would probably then see that the error is at the very end of the query: There's a missing comma.
  5. What, you mean like every other country on the planet? In some countries foreign copyrights are not valid because they haven't signed treaties requiring them to. http://en.wikipedia.org/wiki/List_of_parties_to_international_copyright_treaties That is why international copyright laws exist. Even if countries aren't responsible enough some papers, doesn't make it legal or ethcial for someone to fly to another country and copy your work. Who ever said someone flew to another country to steal this person's scripts? If someone makes their content available in another country then they must be willing to abide by the laws in that country. Unfortunately, or fortunately depending on your perspective, it's difficult to filter who can view your content based upon the country they live in (Yes you can try and filter IPs and such, but they can just use a proxy). From the US Copyright Office (emphasis added): http://www.copyright.gov/fls/fl100.html As you can see it says "most" and not "all".
  6. I don't know jack about Flash. But, you can certainly do what you describe. I'm just not certain that a flash object will initiate correctly. I'll let you figure that out. Here is some rough code: <html> <head> <script type="text/javascript"> function showFlash(objID, source, width, height, seconds) { milliseconds = seconds * 1000; //Convert to milliseconds var embedCode = '<embed type="application/x-shockwave-flash"'; embedCode += ' pluginspage="http://www.adobe.com/go/getflashplayer"'; embedCode += ' width="'+width+'" height="'+height+'" src="'+source+'" />'; embedCode += '<noembed><p>Alternative content</p></noembed>'; document.getElementById(objID).style.display = 'inline'; document.getElementById(objID).innerHTML = embedCode; window.setTimeout("hideFlash('"+objID+"')", milliseconds); } function hideFlash(objID) { document.getElementById(objID).style.display = 'none'; } window.onload = function xxx() { showFlash('flashDiv', 'path/flash_movie.swf', 300, 150, 5); } </script> </head> <body> <div id="flashDiv" style="display:none;"></div> </body> </html>
  7. A few comments: 1. Put your javascript int he head of your document, or better yet, make it an external file that you include. 2. make your code portable. In this example, I would pass the id of the field I want to display the output in instead of hardcoding the value. 3. Don't use 'id' as a variable name - stay away from any names that could conflict with your code (e.g. element, document, etc.). 4. If yu do the same thing over and over, create a function: such as padding your numbers with zero. 5. Don't create variables that you will only use one (e.g. time and today). It's a waste in my opinion. I would make an exception for day, month, hour, etc. as it makes the code easier to implement. here is somethign how I would do it: <html> <head> <title>Test</title> <script type="text/javascript"> <!-- function padZero(numVal) { return (numVal<10) ? '0'+numVal : numVal; } function display(spanID) { var currentTime = new Date() var day = padZero(currentTime.getDate()); var month = padZero(currentTime.getMonth() + 1); var year = padZero(currentTime.getFullYear()); var hours = padZero(currentTime.getHours()); var minutes = padZero(currentTime.getMinutes()); var secs = padZero(currentTime.getSeconds()); var ap = (hours>11) ? 'PM' : 'AM' ; var today = day + '/' + month + '/' + year + ' '; today += hours + ':' + minutes + ':' + secs + ' ' + ap; document.getElementById(spanID).innerHTML = today + " "; setTimeout("display('"+spanID+"')",1000); } window.onload = function() { display('outputSpan'); } //--> </script> </head> <body> The current date and time is - <span id="outputSpan">[loading...]</span><br /><br /> </body> </html>
  8. Yes and no. First off you cannot have elements using the same ID. IDs must be uniqe. You could do something where you have id="name1", id="name2", etc. That's not true. YOU are the programmer, it would be VERY easy to do something like that. I don't know enough about your situation and data to give a comple solutino, but I can provide an example. First off you need some way to determine which fields you need to run this script on. So, let's say for ALL the fields you are getting from the database you put in an identifier field for the ID. So, for these particular checkbox fields use a specific identifier, let's call it 'item'. Well, you should have something in your code that is dynamically writing these fields to the page. Just insert some code to check if the identifier == 'item' if so use item plus the item counter as the id. function displayfield($fieldData) { global $itemCount; $itemCount++; if ($fieldData['id'] = 'item') { $fieldData['id'].=$itemCount; } //rest of script to display the field } Then in the javascript function have the script simply iterrate through each field where the ID begins with 'item' until there are no more: function setItems(checkObj) { var checkCount = 0; var maxChecks = 3; divObj = document.getElementById("checkGroup"); var itemNum = 1; //Determine the number of checked boxes while (document.getElementById('item'+itemNum)) { fieldObj = document.getElementById('item'+itemNum); if (fieldObj.checked) { checkCount++; } itemNum++; } var itemNum = 1; //Enable/disable unchecked boxes while (document.getElementById('item'+itemNum)) { fieldObj = document.getElementById('item'+itemNum); if (fieldObj.checked) { fieldObj.disabled = (checkCount==maxChecks); } itemNum++; } } Note, this was a very quick edit I did not test or validate the above. This was only to give you a general idea of the process.
  9. i'm pretty sure its against some kind of copyright though to steal someones images and content.. Of course you are assuming this person resides in a country that abide's by your country's copyright laws. You don't know who this person is or where they live. You could spend a lot of money trying to determine those things and still not be able to file suit. As for your statement that the person would not have access to the server: if that was the case they would not be able to steal your PHP code as you stated in your initial post. Anyone can copy the HTML code generated on a page, but accessing the PHP code is a different thing entirely.
  10. There is no clear cut answer. First off, 'how' did they ghet your content? hey would have had to have direct server access, so did they get that legally? Also, where you live, where the other person lives and where the server is located will have a lot to do with the legality and where you would have to file suit. Do you know who stole it? If you only have an IP address youwould have to find out the person's IP address and suppeona their ISP. That might be difficult unless you can prove someone stole the code to begin with.
  11. I can't think of any reason why it would break. Can you provide a link to a page with the problem in question?
  12. Psycho

    logic help

    http://www.amazon.com/Beginning-Programming-Dummies/dp/0470088702/ref=pd_bbs_1?ie=UTF8&s=books&qid=1217100679&sr=1-1
  13. Psycho

    logic help

    Logic is not PHP specific. Any PHP book is going to focus on, you gussed it, PHP. I suggest you look for a basic programming book. Programming logic is not language specific.
  14. Change || to && if($_POST['Author'] == "" && $_POST['Title'] == "") { print "An error has occured. Author and Title require input"; }
  15. If you are correctly saving the data to a session variable, then there is no need to send it on the query string. I prefer to use session data for "filtering" criteria in my pagination scripts. Then you just use your normal logic for pagination and insert the filtering criteria into the query if it exists in the session data.
  16. You don't. You posted a function and in return you were provided a new function. So, you don't implement this code into that one, you replace that code with this code. Replace the drag() funtion with the dragIt() function. Change the name to 'drag' if you want.
  17. OK, not to be mean, but there are no echo's or print calls, so why would anything be written tot he page. The function only create a variable and returns it. But, your call to the function only assignes the value to another variable and does not write it ot the page. Try changing your function call to <?php echo showCatigories(); ?> EDIT: By the way, it should be spelled "catagories".
  18. If the OP stated he needed to search using wilecards or regular expressions then, by all means, preg_match() woud be the way to go. But his request didn't mention any such thing and the manual for preg_match() clearly states:
  19. That depends. Without knowing how this is to be implemented I don't know how best to build a solution. It could be included in the function or not. here is one solution: <?php function textsearch($desriptionStr, $searchAry) { $matchAry = array(); foreach ($searchAry as $searchStr) { $matchAry[] = $searchStr; } return $matchCount; } $search_strings = array('joomla', 'web design'); $description = "i need some joomla and web design work done"; $matches = textsearch($description, $search_strings); echo "There are " . count($matches) . " matches"; if (in_array('joomla', $matches)) { $site = f_open("http://www.google.com"); } if (in_array('web design', $matches)) { //Do something else } ?>
  20. That's a little much. Also, preg_match is not very efficient for this: <?php function textsearch($desriptionStr, $searchAry) { $matchCount = 0; foreach ($searchAry as $searchStr) { $matchCount += (strpos($desriptionStr, $searchStr)!=false); } return $matchCount; } $search_for = array('joomla', 'web design'); $the_items_description = "i need some joomla and web design work done"; echo "There are " . textsearch($the_items_description, $search_for) . " matches"; ?>
  21. Well, you could do it with just CSS <html> <body> <select onchange="presentData(this);" id="dbTbls" style="color:#ffffff;"> <option style="background-color:#0000ff;" value="#0000ff">Blue</option> <option style="background-color:#ff0000;" value="Hello Universe!">Red</option> <option style="background-color:#00ff00;" value="Hello Foo!">Green</option> </select> </body> </html> But that limits you to specific values and the user can't enter custom values. I would suggest something like this which let's the user select some predefined values or enter custom values (you would need to add some validation for user entered values): <html> <head> <script type="text/javascript"> function changeColor(inputObj) { if (inputObj.value) { document.getElementById('hex').value = inputObj.value; showColor(inputObj.value); } else { document.getElementById('hex').value = ''; showColor(inputObj.value); } return; } function customColor(outputObj) { document.getElementById('colorSel').value = outputObj.value; if (document.getElementById('colorSel').value != outputObj.value) { document.getElementById('colorSel').selectedIndex = 0; } showColor(outputObj.value); return; } function showColor(colorVal) { if (colorVal) { document.getElementById('test').style.backgroundColor = colorVal; document.getElementById('test').style.border = '1px solid black'; } else { document.getElementById('test').style.backgroundColor = '#ffffff'; document.getElementById('test').style.border = ''; } return; } </script> </head> <body> Color: <select onchange="changeColor(this);" id="colorSel" style="color:#ffffff;"> <option value="" style="color:#000000;">--Select Color--</option> <option style="background-color:#0000ff;" value="#0000ff">Blue</option> <option style="background-color:#ff0000;" value="#ff0000">Red</option> <option style="background-color:#00ff00;" value="#00ff00">Green</option> </select><br> Hex Value: <input type="text" id="hex" name="hex" onchange="customColor(this);"><br> <div id="test" style="width:80px; height:40px;"></div> </body> </html>
  22. I'm not sure. You could also just copy the contents of the temp directory to the existing directory. But, both of those methods have a flaw. If you have any file in the existing directory that does not exist in the temp directory, then copying or overwriting will not remove those unneeded files.
  23. The best way to do this, from my perspective, would be to delete the existing directory and rename the temp directory. The 2nd post on this PHP manual page has a function to delete an entire directory that has contents. http://us.php.net/manual/en/function.unlink.php Then rename using this command: http://us.php.net/rename
  24. Your original code had a few problems: 1. You had no closing select tag. 2. In the onchange event the id was passed as a variable (that had not been defined) and not as text. It would be easier to use the global 'this' variable: Here's your original code with corrections: <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <script type="text/javascript"> function presentData(field) { document.getElementById('numRows').innerHTML = field.value; } </script> <body> <select onchange="presentData(this);" id="dbTbls"> <option value="Hello World!">Hello World!</option> <option value="Hello Universe!">Hello Universe!</option> <option value="Hello Foo!">Hello Foo!</option> </select> <br /> <div id='numRows'></div> </body> </html>
  25. Nice one lemmin, that can be reduced greatly by using some math function dragIt(e) { w = parseInt(e.style.width); h = parseInt(e.style.height); self.document.onmousemove=function() { e.style.left = Math.floor((event.clientX)/w)*w; e.style.top = Math.floor((event.clientY)/h)*h; return false; } self.document.onmouseup=function() { self.document.onmousemove=null; } }
×
×
  • 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.