Psycho
Moderators-
Posts
12,157 -
Joined
-
Last visited
-
Days Won
129
Everything posted by Psycho
-
[SOLVED] Dynamically Include PHP File - JS Question
Psycho replied to Ryuujin's topic in Javascript Help
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' -
[SOLVED] You have an error in your SQL syntax
Psycho replied to Thomisback's topic in PHP Coding Help
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. -
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".
-
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>
-
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>
-
limit checkboxes in a form - boxes all differnent names
Psycho replied to scotchegg78's topic in Javascript Help
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. -
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.
-
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.
-
Trying to make a search engine, without using innerHTML
Psycho replied to tibberous's topic in Javascript Help
I can't think of any reason why it would break. Can you provide a link to a page with the problem in question? -
http://www.amazon.com/Beginning-Programming-Dummies/dp/0470088702/ref=pd_bbs_1?ie=UTF8&s=books&qid=1217100679&sr=1-1
-
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.
-
[SOLVED] search form - fill at least ONE field
Psycho replied to sirtemplar's topic in PHP Coding Help
Change || to && if($_POST['Author'] == "" && $_POST['Title'] == "") { print "An error has occured. Author and Title require input"; } -
Appending a query string when using Pagination
Psycho replied to worleyjbird's topic in PHP Coding Help
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. -
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.
-
Ok this wont display anything even tho it should.
Psycho replied to Dethman's topic in PHP Coding Help
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". -
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:
-
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 } ?>
-
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"; ?>
-
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>
-
[SOLVED] Theory question writting over a directory
Psycho replied to koolaid's topic in PHP Coding Help
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. -
[SOLVED] Theory question writting over a directory
Psycho replied to koolaid's topic in PHP Coding Help
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 -
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>
-
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; } }
-
There's a small problem with that code in that once it starts - it never stops - even when the text area has reached the bottom of the text. That means it is continually running on the client's machine. I would suggest using scrollheight as a trigger for when the script can be exited (you can always restart the script if the user moved the slider). Of course scroll height will always be greater than scroll top because of the top and bottom scroll buttons, but this will at least exit the script shortly after it reaches the bottom: <html> <head> <script language="JScript"> function txtScroll(textareaID) { textareaObj = document.getElementById(textareaID); textareaObj.scrollTop = textareaObj.scrollTop+1; if (textareaObj.scrollTop < textareaObj.scrollHeight) { setTimeout('txtScroll(\''+textareaID+'\')', 10); } } </script> </head> <body> <textarea id="txtTest" rows=5 onclick="txtScroll(this.id)">TEST Text TEST Text TEST Text TEST Text TEST Text TEST Text TEST Text TEST Text TEST Text TEST Text TEST Text TEST Text TEST Text TEST Text TEST Text TEST Text TEST Text TEST Text TEST Text TEST Text TEST Text </textarea> </body> </html>
-
Why do you need JavaScript validation for a select list? The select list should only contain values that are valid to begin with. You would want to include server-side validation, but client-side validation of a select list is not needed unless some values in a select list are only valid based upon other values in the form. For example, if it was a page to apply for a job you might have an option such as: "Are you a current employee of XYZ Company? Yes/No" Then, a new question with a select list such as: "If not a current employee of XYZ company, how did you hear about us? " In that situation it might be of value to ensure they did not select one of the values in the select list unless they answered no to the previous question (Assuming the first value is null). OR ---- You might want to validate that the user actually selected one of the "Values" from the list if you are using a "Please select a value" as the first option. But, this is very easy to validate by ensuring the item selected is not the first value or not a specific value. Also, most of your isProper() function is worthless. The condition willautomatically return true or false and the rest will not be run at all. What EXACTLY are you trying to achieve? Please state in plain words what you want to validate. Such as "The country should be a string with the following characters a-z, A-Z, underscore, etc. There may be spaces, but they may not begin or end the string and they may not appear in succession."