Jump to content

ginerjm

Members
  • Posts

    6,906
  • Joined

  • Last visited

  • Days Won

    99

Everything posted by ginerjm

  1. I want my Cancel button to send me back to whence I came from. I've researched and found tons of postings saying to do history.go(-1), history.go(), window.location.reload('myurl') and other things - all of which didn't do it. Back is good, but even better would be the ability to provide a url to execute. I want to tie this function(?) to the onclick event of my Cancel button.
  2. Never used it before and after much trial and error and several bad code examples from you-know-where, here I am. Want to display a little countdown on my re-direct page. Set up a counter function and a display-it function. Counter function is called by "onload="CountDown()" in the "body" tag of my html Here are the functions. var sttime = 5; function myTimer() { document.getElementById('timerbox').innerHTML=sttime+" seconds to go"; sttime = sttime - 1; return; } function CountDown(tm_val) { myTimer(); while (sttime >0) { var t=window.setTimeout(myTimer,1000); } return; } Note that the var 'sttime' is global and is used in both functions. Note also that 'timerbox' is an h2 element in my webpage. The goal is to display the initial value (which works), then to display a reduced value every second after that until the value becomes 0. What happens is I see a 5 displayed (the starting point) and then a 0 on the next display, and then nothing changes. Actually I think I'm hanging up my server since response dies after that. Are my functions valid?
  3. With the help of this forum I have learned to use json-encode to take the results of a mysql query in php and build a JS array to use in a JS function on my page to supply looked up names in response to a entered number value. Works great! The code that displays the results is the same code (same exact lines) thta gets used on a copule of different screens for different purpose. Here's the problem. I created a new screen layout using the code by adding some line breaks basically using html to re-arrange my input screen to make a better layout for printing. That's all. But - on 2 of my screens names stored in my table such as O'Meara show up just fine, on the 3rd (new) screen this name shows up as O\'Meara. Thinking that I probably needed to add the slash to the database and then use PHP "stripslashes" to remove it when I retrieved it, I added that to my query results process. It still shows up with the slash. In fact, I played around and added an apostrophe to another entry on the table and re-ran the code and now I get a \ in both names, but only on the one screen. So - I went back and removed the slash from the one table entry that I put it in and it still shows up on this one screen with a slash. I am absolutely positive that the same line of html/php is producing the output for all 3 screens, so what could be doing this in one situation only? I've looked at the html file that is being displayed and there is no embedded \ character in the guy's name, EXCEPT in the place where the html is displaying it in the value= parameter. The JS array does not have a \ character in hte guy's array element. Some code pieces below this is how I retrieve the data from the table and build the php array: $golfers["$gnum"] = stripslashes($row['golfer']); this is how I create the js array: var jsgolfers = <?php echo json_encode($golfers); ?>; this is how I retrieve the array element and place in into the html input tag (name="pickname"+a number in 'str') document.getElementById("pickname"+str).value = stripslashes(jsgolfers[choice]);
  4. you da man! That was the simplest fix I've ever been given in all my years on many different forums for many different subjects. Thank you very much.
  5. ok - I have an assoc php array that works just like I want it to. The indices of it are not 0.....n but instead the assigned numbers I have in my sql table. I use this to build my js array var jsgolfers = ["<?php echo implode("\",\"",$golfers); ?>"]; which builds just a normal enumerated array, even tho the indices of $golfers are not enumerated. So - while php tells me that $ar["4"] (which is actually the 2nd element) is "Tiger", JS says it is a couple more cells down the line and shows "Phil". Any way of managing this in JS?
  6. After much research and some great tips, I have managed to move a php generated query/array to a js array. My code works great and all but what I need to do now is to make the js array an "associated" one. Ex. my php query produces a result of 1 Tiger 4 Phil 3 Nick I can make an assoc array in php that would look like: $ar["1"] = "Tiger" $ar["4"] = "Phil" instead of $ar[0] = "Tiger" $ar[1] = "Phil" How can I get the assoc php array format into a js array so that I can do a look up on a value of "4" and come up with "Phil" instead of undefined? Does JS even have associative arrays?
  7. Lifted from examples on "helpful" web pages. I had to modify that just to get a response out of it - which took me hours!
  8. Eureka! After dumping my generated html page to an editor I saw that someone (php? js?) was inserting error messages (<a .....> even) into my html and that was causing a lot of trouble apparently. I massaged my code and this now does what I expect. echo '<script type="text/javascript">'; ?> var jsgolfers = ["<?php echo implode("\",\"",$golfers); ?>"]; <?php echo 'function gn(str)'; echo '{'; echo 'alert(jsgolfers[str]);'; echo '}'; echo '</script>'; Basically - the $golfers array is built using php and sql early in my script. then the js creates a global array and loads it from $golfers. Then my onclick attribute on a d/e field calls the function which properly displays the corresponding golfer depending upon the input I entered.
  9. And Yes - I have tried using a reference to $jsgolfers as well as just plain jsgolfers.
  10. Been reading all afternoon. Here is where I am at with ONE big error. Everytime I call the function 'gn(n)' I get the message that "jsgolfers is undefined'. echo '<script type="text/javascript">'; echo 'var jsgolfers = new array["<?php echo join(":\", $golfers); ?>"];'; echo '</script>'; echo '<script type="text/javascript">'; echo 'function gn(str)'; echo '{'; echo 'alert(jsgolfers[$str]);'; echo '}'; echo '</script>'; First - the $golfers array is created and has values which I've displayed on my page I've had a lot of difficulty with the join function - the example I found on the web didn't work so I've whittled it down to what it is. Will appreciate any pointers one can provide. Supposedly this code will take a php-produced array var and build a JS array var for me to use in an onclick event on my page.
  11. Please disregard my post. It dawned on me (once again) that I've made a major mistake in my solution by trying to combine php session vars with js execution. I'll get it down pat one of these days. That said (admitted!) - how would a decent js programmer tackle this problem. d/e form to collect a series of picks from the user. The form should do an immediate display of the associated "names" of the picked items (numbers). There are 12 entries to be made on the form so whatever solution is developed has to be executed 12 times on each form. I had considered doing queries for each change but thought that inefficient, hence my original idea of a session array (which won't work). Can js develop an array (once) to then be used in a js function call that will happen multiple times?
  12. I have a d/e form that has a series of numbered fields - Player1,Player2,Player3... followed by another series - Playername1,Playername2,Playername3... They are related by number naturally. What I want to do is use js to populate the corresponding Playername field when its 'partner' Player field has been modified. So far I've figured that in the html input tag for 'Playern' I would have an 'onchange="gn($i)"' where 'gn($i)' is the function that will pull my name values from a session array i've already built. My question is - how do I post the looked up value to the name field? here is my proposed function header: echo '<script type="text/javascript">'; echo 'function gn(str)'; echo '{'; this is where the lookup to my session array would occur and the posting of the result to my name field. echo '}'; echo '</script>'; here are my current input tags echo '<td><input onchange="gn($i)" type="text" name="Player'.$i.'" tabindex="1'.$i.'" size="4" maxlength="2" value="'.$_POST["Player$i"].'"></td>'; echo '<td><input '.$n_attr.' id="pad" type="text" name="Player'.$i.'" size="25" maxlength="25" value="'.$_POST["Playername$i"].'"></td>'; The input tags are in a for loop controlled by $i. So for any given 'player(n)' field I want to look up in my array for element (n) and then post the array's (n) value to the input tag called 'Playername(n)'. Is this easily doable?
  13. ok - I see the concept of burying an anchor in my td. Thanks!
  14. Now that I've discovered that the HTML TABLE element doesn't support a name attribute or a tabindex one, and neither do the TR or TD elements I'm wondering if JS can come to my rescue. I'm new to it and don't find anything so far on this feature I've used simple xx.xx.focus statements in onclick events or onload events, but since I can't set a name attribute on a table or td element, I can't do that here. Any possibilities here?
  15. I've never 'called' a function before, just used it as the target of an event ie, onclick="functionname". I'm trying to do so in a little test php script to try out some stuff I got out of Resig's book. in the html head section i have my script tag and the function in the body i have some echo statements trying to output the results of a call to the function echo 'paragraph contains'.getText("p1"); I get an undefined function error when I run this. Is there some special syntax for 'calling' a js function? I can't seem to find anything in the book on this.
  16. Everything I know about the web is from w3schools!!! Without that there is nothingness! where would you suggest I get my nourishment - for js at least?
  17. Found it. The field I was trying to set I hadn't put an ID attribute on. The only one missing it!
  18. wouldn't it help if you told us what it wasn't doing anymore?
  19. ok - nobody seems to know much about js on the iphone - errors that is. So - in the meantime I've been experimenting and come up with this so far. function CopyResult() { var x=document.getElementById("curdirs").value; try { 1 var str = x; 2 var arstr = str.split(" "); 3 if (arstr.length >1) { 4 document.getElementById("mntstsy").checked = true; } 5 else { 6 document.getElementById("mntstsn").checked = true; } 7 str = arstr.shift(); 8 alert("shift done- now using: "+str); 9 document.getElementById("uid").value =str; 10 alert("set uid"); This function is called from an html "select" tag using the onchange event. I've tried several alerts in the function and find that I'm getting thru it up until I try to set the "uid" input tag in line 9 with the value in the var "str". The alert following this line doesn't get executed. I do know that I have values that are good as I've seen them using alerts, and I can see that the actions performed by lines 4 or 6 get performed. But then it dies giving me an error message of "undefined". Does anyone have a clue why line 9 fails on safari (iphone) and runs just fine on IE?
  20. I've read the rules and the help but I don't see how it's done. No buttons on any screens. If I get the solution or figure it out in the meantime, I'd like to mark the post solved.
  21. OK - here is a function I made (cut and pasted essentially) that works great on my laptop. But on my iphone it gives me an error. The error is vague - err.description reports as: "undefined". Here's the code, which as I said works great on ie. Basically it grabs the selected item from a dropdown menu ("curdirs") and copies it (after a little cleanup) onto some other input fields. <script type="text/javascript"> function displayResult() { var x=document.getElementById("curdirs").selectedIndex; var y=document.getElementById("curdirs").options; try { var str = y[x].text; var arstr = str.split(" "); if (arstr.length >1) document.getElementById("mntstsy").checked = true; else document.getElementById("mntstsn").checked = true; str = arstr.shift(); document.getElementById("uid").value =str; document.getElementById("dirstsy").checked = true; document.getElementById("dirstsy").focus(); } catch(err) { txt="There was an error on this page.\n\n"; txt+="Error description: " + err.description + "\n\n"; txt+="Click OK to continue.\n\n"; alert(txt); } } The code gets triggered by the onclick event. I've tried onchange, onblur for the iphone becuase of some posts I read, but all that does is eliminate the error popup - it still doesn't do anything on the iphone. Yes - I have read about the lack of support for the "select" tag on Safari, but I'm hoping someone has this a clue why this js doesn't work. I certainly don't - I have all of 3 days of experience in it!
  22. I just came back online to post that I had solved this - only to see the very first response telling me the same thing. The code was all lifted from a posting I found online, so it wasn't my fault. I did finally see it though after doing some reading on how classes worked. Thanks for the quick response tho!
  23. ok - I lifted some code to help identify the client's browser (damn iphone doesn't like my "select" tag). The code was this class definition and was followed by a couple lines showing how to use it. Here are the two lines: $browser = new Browser ; echo "Using: $Browser->Name $Browser->Version" ; When I include the class and add these two lines to my script all I get is the word "using:' displayed. Is it possible that the writer of this code left something out? I don't know what the syntax of the "x->y" references are, but shouldnt' there be a call to functions within the class?
  24. sorry - just joined this forum for some js help and now, with my php problem, I just slipped up. :(
×
×
  • 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.