Psycho
Moderators-
Posts
12,157 -
Joined
-
Last visited
-
Days Won
129
Everything posted by Psycho
-
It looks as if the field type for worth is a text field and not a numeric field. If you order those values as if they were text then the results you are getting is correct: a 2 comes before a 5 just as B comes before F. Change the field type of "worth" to an appropriate numeric field. EDIT: You also have several unnecessary lines. No reason to create the variable $number just to use it one on the next line: <?php $query = "SELECT * FROM profile ORDER BY worth ASC"; $result = mysql_query($query) or die (mysql_error()."<br>$query"); $i = 1; while($row = mysql_fetch_array($result)) { echo $i++ . number_format($row['worth'], 2, '.', ','); } ?> And whay are you not following the advice you are including in your own sig?
-
There is no reason that a server-side page used for AJAX needs to be on the same domain that the page with the calling javascript is on.
-
<?php $contents = file_get_contents($url); $pattern = '/(Hellow my name is: )(.*)( my lastname is)/'; preg_match($pattern, $contents, $matches); $firstname = $matches[2]; ?>
-
Assuming that "formDLL" is a form name and "emailALL" is a field name in that form, I don't see nay problem with that. COuld you post more of the code and explain what the error is?
-
There was some errors in the echo code. I fixed that and made it more modular. Try this: <?php $file_types = array('gif','jpg'); $directory = 'image'; foreach(scandir($directory) as $thumb) { if (is_file("$directory/$thumb") && in_array(end(explode('.', $thumb)), $file_types)) { echo "<img src=\"$directory/$thumb\" width=\"200\" height=\"200\">"; echo "<a href=\"$directory/$thumb\">View Normal Size</a>"; } } ?>
-
<?php $file_types = array('gif', 'jpg'); foreach(scandir('image') as $thumb) { if (is_file($thumb) && in_array(end(explode('.', $thumb)), $file_types)) { echo '<img src="image/', $thumb, '"/ width="200" height="200">'; echo '<a href="image/', $thumb, '"/>View Normal Size</a>'; } } ?>
-
BY the way, I believe there is a problem with the isProper function you posted above: function isProper(string) { if (string.search(/^\w+( \w+)?$/) != -1) return true; else return false; if (!string) return false; var iChars = "*|,\":<>[]{}`\';()@&$#%"; for (var i = 0; i < string.length; i++) { if (iChars.indexOf(string.charAt(i)) != -1) return false; } return true; } The first IF/ELSE statemetn will either return true or false, so everything after that is never run. This should fix it if I am reading it correctly: function isProper(string) { if (string.search(/^\w+( \w+)?$/) == -1) return false; if (!string) return false; var iChars = "*|,\":<>[]{}`\';()@&$#%"; for (var i = 0; i < string.length; i++) { if (iChars.indexOf(string.charAt(i)) != -1) return false; } return true; } Also, you could replace the for loop with a single regex pattern.
-
I hear what you're saying. I thought thre was a way to escape the outer quotes as well. But I wasn't able to figure out a solution after several minutes of testing. So, as long as there is an acceptable solution I wouldn't waste too much time trying to figure it out.
-
Just use the HTML character code(s): <html> <Head></head> <body> <div onMouseOver="self.status='A test with (\') single quote.';">This shows a single quote</div><br> <div onMouseOver="self.status='A test with (") double quote.';">This shows a double quote</div><br> <div onMouseOver="self.status='A test with (\') (") both quotes.';">This shows both quote makrs</div><br> </body> </html>
-
<?php echo "<script type=\"text/javascript\">\n"; echo " var jsVariable = $phpVariable;\n"; echo "</script>\n"; ?>
-
It would help tremendously if you posted some of details such as the form fields and the database fields, but here is an example: <?php if (isset($_POST)) { $whereClauses = array(); if ($_POST['eye_color']) { $whereClauses[] = "eye_color='{$_POST['eye_color']}'"; if ($_POST['hair_color']) { $whereClauses[] = "hair_color='{$_POST['hair_color']}'"; if ($_POST['age']) { $whereClauses[] = "age='{$_POST['age']}'"; $query = "SELECT * FROM users WHERE " . implode(' AND ', $whereClauses); $result = mysql_query($query) or die mysql_error(); } ?>
-
function show(divID, checkedState) { code = (checkedState)? 'test' : ''; document.getElementById('counterDiv').innerHTML = code; } Number of plays:<input type="checkbox" name="counter" value="1" onclick="show('counterDiv', this.checked);"> <div id="counterDiv"><div>
-
It makes perfect sens to me. I think you are confusing the parameter value and a string value. You don't escape quortes for the paramater, but you do for the string. Here is one of the examples where you say it doesn't work: Here is the parameter value: onMouseOver="self.status='te\"st';" Here is the string value: onMouseOver="self.status='te\"st';" It is defined with single quotes, so any single quotes in the string must be escaped.
-
Please help, Seems to keep running don't know why???
Psycho replied to morfusaf's topic in Javascript Help
OK, I think the problem here is that you are running document.write() after the page has loaded. If you run the script in IE and then do a view source you will see that the "content" of the page only includes the text that was written to the page using the document.write()'s. All the HTML markup and javascript is gone. FF must be getting confused by this. If you use document.write during page load this does not occure. This also explains why "refreshing" the page has no effect. The original code no longer exists in the browser so refreshing has no effect. You should follow rhodesa's advice and use a div and add the text to the div using innerHTML. I just rewrote your code using that method and it works perfectly. -
Please help, Seems to keep running don't know why???
Psycho replied to morfusaf's topic in Javascript Help
Hmmm, didn't know you could do ++x Ok, well I just copied and pasted the code into a new page and it worked fine for me in IE (assuming the two line breaks in the document.write() calls were supposed to be BR tags. It only stall in FF. -
Please help, Seems to keep running don't know why???
Psycho replied to morfusaf's topic in Javascript Help
I'm resisting the temptation to "fix" all of your code. But, for this particular problem. This: for(count = 0; count != how_many; ++count) {[code] Should be this: [code] for(count = 0; count != how_many; count++) {[code] (The double plus (++) comes after the variable to increment it by 1. [/code][/code][/code] -
You have set the "names" to be an array, but you are trying to grab that array using getElementById(). And, you can't give multiple elements the same ID anyway. Instead reference the collection by their name as an element of the form: <html> <head> <script type="text/javascript"> function countBoxes() { alert(document.forms[0]['zone_type[]'].length); } </script> </head> <body> <form> Check 1 <input type="checkbox" name="zone_type[]" value="1"><br> Check 2 <input type="checkbox" name="zone_type[]" value="2"><br> Check 3 <input type="checkbox" name="zone_type[]" value="3"><br> <button onclick="countBoxes();">Check</button> </form> </body> </html>
-
[SOLVED] Using JS to change selected value of a dropdown
Psycho replied to kjtocool's topic in Javascript Help
For the record, eval is something to steer away from if at all possible. Using it opens you up to many potential problems. -
[SOLVED] Using JS to change selected value of a dropdown
Psycho replied to kjtocool's topic in Javascript Help
What is the purpose of eval? A better option, IMHO, would be this: var dropdown = movie_rankings['movie_' + old_rank + '_rank']; Then you can simply set the selected value like this: dropdown.value = 'newvalue'; As long as newvalue exists in the values of the options options it should be selected. Note that the value of an option is not necessarily the same as the text of the option (which is what the user sees). To set the option of a select list based upon the text you must iterrate through every option until you find a match. -
Hmmm, I would think you could achieve that with a modified RegEx, but I couldn't figure it out. Here's a quick fix: function getIDs (string) { var IDs = string.match (/id_\d{1,9}/g); for (var i=0; i<IDs.length; i++) { IDs[i] = IDs[i].substr(3); } return IDs; } var ID = getIDs (document.body.innerHTML);
-
<html> <head> <script language="Javascript" type="text/javascript"> function checkForm(formObj){ var double = false; for (var row=1; row<=8; row++) { var rowCount = 0; for (var col=1; col<=3; col++) { if (formObj['chk-'+row+'-'+col].checked) { rowCount++; } } if (rowCount==0) { alert('You must select at least one checkbox from each row'); return false; } if (rowCount>2) { alert('You may not select more than two checkboxes from any row'); return false; } if (rowCount==2) { if (double) { alert('You may not select two checkboxes in more than one row'); return false; } else { double = true; } } } if (!double) { alert('You must select two checkboxes in one of the rows'); return false; } return true; } </script> </head> <body> <form name="theform" onsubmit="return checkForm(this);"> <table border="1"> <tr> <td> </td> <td>1</td> <td>2</td> <td>3</td> </tr> <tr> <td>1</td> <td><input type="checkbox" name="chk-1-1"></td> <td><input type="checkbox" name="chk-1-2"></td> <td><input type="checkbox" name="chk-1-3"></td> </tr> <tr> <td>2</td> <td><input type="checkbox" name="chk-2-1"></td> <td><input type="checkbox" name="chk-2-2"></td> <td><input type="checkbox" name="chk-2-3"></td> </tr> <tr> <td>3</td> <td><input type="checkbox" name="chk-3-1"></td> <td><input type="checkbox" name="chk-3-2"></td> <td><input type="checkbox" name="chk-3-3"></td> </tr> <tr> <td>4</td> <td><input type="checkbox" name="chk-4-1"></td> <td><input type="checkbox" name="chk-4-2"></td> <td><input type="checkbox" name="chk-4-3"></td> </tr> <tr> <td>5</td> <td><input type="checkbox" name="chk-5-1"></td> <td><input type="checkbox" name="chk-5-2"></td> <td><input type="checkbox" name="chk-5-3"></td> </tr> <tr> <td>6</td> <td><input type="checkbox" name="chk-6-1"></td> <td><input type="checkbox" name="chk-6-2"></td> <td><input type="checkbox" name="chk-6-3"></td> </tr> <tr> <td>7</td> <td><input type="checkbox" name="chk-7-1"></td> <td><input type="checkbox" name="chk-7-2"></td> <td><input type="checkbox" name="chk-7-3"></td> </tr> <tr> <td>8</td> <td><input type="checkbox" name="chk-8-1"></td> <td><input type="checkbox" name="chk-8-2"></td> <td><input type="checkbox" name="chk-8-3"></td> </tr> </table> <button type="submit">Submit</button> </form> </body> </html>
-
I'm guessing it may have something to do with the fact that you have your code within a table. If you try to put text between table tags that are not also within TD tags strange things may happen. Check the HTML output to see if that message is there and then determine how to format that erro message to correctly display on the page.
-
<html> <head> <script type="text/javascript"> // State lists var states = new Array(); states['Canada'] = new Array('Alberta','British Columbia','Ontario'); states['Mexico'] = new Array('Baja California','Chihuahua','Jalisco'); states['United States'] = new Array('California','Florida','New York'); // City lists var cities = new Array(); cities['Canada'] = new Array(); cities['Canada']['Alberta'] = new Array('Edmonton','Calgary'); cities['Canada']['British Columbia'] = new Array('Victoria','Vancouver'); cities['Canada']['Ontario'] = new Array('Toronto','Hamilton'); cities['Mexico'] = new Array(); cities['Mexico']['Baja California'] = new Array('Tijauna','Mexicali'); cities['Mexico']['Chihuahua'] = new Array('Ciudad Juárez','Chihuahua'); cities['Mexico']['Jalisco'] = new Array('Guadalajara','Chapala'); cities['United States'] = new Array(); cities['United States']['California'] = new Array('Los Angeles','San Francisco'); cities['United States']['Florida'] = new Array('Miami','Orlando'); cities['United States']['New York'] = new Array('Buffalo','New York'); function setStates(){ cntrySel = document.getElementById('country'); stateSel = document.getElementById('state'); stateList = states[cntrySel.value]; changeSelect(stateSel, stateList); setCities(); } function setCities(){ cntrySel = document.getElementById('country'); stateSel = document.getElementById('state'); citySel = document.getElementById('city'); cityList = cities[cntrySel.value][stateSel.value]; changeSelect(citySel, cityList); } //**************************************************************************// // FUNCTION changeSelect(fieldObj, valuesAry, [optTextAry], [selectedVal]) // //**************************************************************************// function changeSelect(fieldObj, valuesAry, optTextAry, selectedValue) { //Clear the select list fieldObj.options.length = 0; //Set the option text to the values if not passed optTextAry = (optTextAry)?optTextAry:valuesAry; //Itterate through the list and create the options for (i in valuesAry) { selectFlag = (selectedValue && selectedValue==valuesAry[i])?true:false; fieldObj.options[fieldObj.length] = new Option(optTextAry[i], valuesAry[i], false, selectFlag); } } </script> </head> <body onload="setStates();"> <form name="test" method="POST" action="processingpage.php"> Country: <select name="country" id="country" onchange="setStates();"> <option value="Canada">Canada</option> <option value="Mexico">Mexico</option> <option value="United States">United States</option> </select> <br> State: <select name="state" id="state" onchange="setCities();"> <option value="">Please select a Country</option> </select> <br> City: <select name="city" id="city" onchange="alert(this.options[this.selectedIndex].value)"> <option value="">Please select a Country</option> </select> </form> </body> </html>
-
That code will "blank out" the user entered value when you click on the field. So, if theusr needs to edit their entered value they have to retype the whole thing. I have a script that is very easy to implement with the following steps: 1. Include the external js file 2. [optional] Create an ".inputPrompt" class so the prompts are displayed appropriately 3. In the text fields that need a prompt, simply add a prompt parameter: <input name="name" type="text" prompt="Enter your name"> 4. Add an onload parameter to run the "initializePrompts()" function. All input's with a prompt parameter will dynamically have an onload and onblur event created. Test Page: <html> <head> <script type="text/javascript" src="input_prompts.js"></script> <style> .inputPrompt { font-style:italic; color: #969696; } </style> </head> <body onload="initializePrompts()"> Name: <input name="name" type="text" prompt="Input Name"> </body> </html> External js file "input_prompts.js": function initializePrompts() { var oinputs = document.getElementsByTagName('input'); for (var i = 0; i < oinputs.length; i++) { //insert the prompt text if there is a prompt value if (oinputs[i].getAttribute('prompt')) { createPromptEvents(oinputs[i]); } } var oinputs = document.getElementsByTagName('textarea'); for (var i = 0; i < oinputs.length; i++) { //insert the prompt text if there is a prompt value if (oinputs[i].getAttribute('prompt')) { createPromptEvents(oinputs[i]); } } } function createPromptEvents(fieldObj) { //Create the onfocus event var oldFocus = fieldObj.onfocus; fieldObj.onfocus = function () { if (this.className=='inputPrompt') { this.value = ''; this.className = ''; } } if (oldFocus) { //Restore original focus event try { fieldObj.addEventListener('focus', oldFocus, true); } catch (e) { fieldObj.attachEvent('onfocus', oldFocus) } } //Create the onblur event var oldBlur = fieldObj.onblur; fieldObj.onblur = function () { if (this.value=='') { this.value = this.getAttribute('prompt'); this.className = 'inputPrompt'; } } if (oldBlur) { //Restore original blur event try { fieldObj.addEventListener('blur', oldBlur, false); } catch (e) { fieldObj.attachEvent('onblur', oldBlur) } } //Set the initial prompt value fieldObj.focus(); fieldObj.blur(); } function loadPrompts(loadSwitch) { //ADD TO ONSUBMIT FORM EVENTS //Load or unload the prompts var oinputs = document.getElementsByTagName('input'); for (var i = 0; i < oinputs.length; i++) { loadSinglePrompt(oinputs[i], loadSwitch); } var oinputs = document.getElementsByTagName('textarea'); for (var i = 0; i < oinputs.length; i++) { loadSinglePrompt(oinputs[i], loadSwitch); } } function loadSinglePrompt(fieldObj, loadSwitch) { //insert the prompt text if there is a prompt value if (fieldObj.className=='inputPrompt') { if (loadSwitch) { fieldObj.focus(); fieldObj.blur(); } else { fieldObj.value=''; } } return; }
-
[SOLVED] How do I pass two variables from php to java script?
Psycho replied to Hardwarez's topic in Javascript Help
Well, an AJAX implementation has many steps tothe process and if any fail the result will fail. Add some debuggin code to validate that values are what you expect at each step. The first thing I would do is add the following alert: function handleResponse() { if(http.readyState == 4){ var response = http.responseText; alert('AJAX Response: ' + response); var update = new Array(); if(response.indexOf('|' != -1)) { update = response.split('|'); document.getElementById(update[0]).innerHTML = update[1]; } } } That will tell you if the correct value is being returned from AJAX. If not, then you need to look further up in the process. Aslo, you coul do a quick check by going directly to the AJAX page in our browser: http://www.yourdomain.com/dynamic.php?job=testvalue Is the correct response displayed inthe browser? If not, the PHP page is malfunctioning.