havenpets
Members-
Posts
28 -
Joined
-
Last visited
Never
Profile Information
-
Gender
Not Telling
havenpets's Achievements
Newbie (1/5)
0
Reputation
-
Okay, so I am creating a Jquery registration page using "dialog". I am using the "jquery" version of AJAX. It's pretty similar, and the problem I am having can happen to either. Basically this is how my code is organized: function go_ajax(formtype){ formvalue = document.getElementById(formtype).value; $.get("/xatron/check.php?type="+formtype+"&value="+escape(formvalue), function(data) { // TEST alert(data); return data; }); } Data = httpObject.responseText Thats the same as a "get" script in AJAX. Now, later in my code I have... if(go_ajax('username') == 0){ // Fail }else{ // Pass } Now, it will come up as "Pass" EVERYTIME because... go_ajax('username') = undefined. But when I do the test and do the alert above it presents to me, 0 or 1. x_X And it alerts AFTER undefined alerts. How would I go about fixing this? Anyone know? (p.s. YES, I know this is jquery BUT ajax is the exact same problem (i've tried both methods). Thank you, Matt
-
function check_form(){ httpObject.onreadystatechange = function() { if(httpObject.readyState == 4){ run_ajax(httpObject.responseText); } } } function run_ajax(solution){ if(solution == 0){ $("#"+formtype).addClass('ui-state-error'); updateTips("This "+formtype+" already exists in our database."); return false; }else{ return true; } } (later in coding) function (){ var bValid = true; bValid = bValid && check_form("username"); if(bValid){ alert("SUCCESS"); } (I took out all the unnecessary coding. The problem lies with it not saying success even though it is! When I alert bValid before the if(), it says "undefined". Anyone know a way around this?
-
I worked around IE's caching... random = Math.floor(Math.random()*999999); and added +"&random="+random to the URL so it's a different link every time!
-
Lol wow why was I thinking forms with the "GET" and "POST" thing? Ha ha Sorry about that!
-
In Google chrome and Firefox my script works wonders. It looks amazing! However, in internet explorer there seems to be a minor problem. Once a login credential has been submitted (e.g. Username: hi, Password: hi) you cannot submit the form again with the same credentials. Seems like a security thing IE does so it's not viewing the same web page as before. Code: function check_credentials(){ httpObject = getHTTPObject(); if (httpObject != null) { httpObject.open("GET", "/xatron/login.php?username="+escape(document.getElementById('username').value)+"&password="+escape(document.getElementById('password').value), true); httpObject.send(null); httpObject.onreadystatechange = function() { setOutput(); } } } function setOutput(){ if(httpObject.readyState == 4){ // alert(httpObject.readyState); *** This is a test line... login_run(httpObject.responseText); } } function login_run(login_answer){ login_answer = login_answer; if(login_answer == 0){ // alert false }else{ document.location.href='/xatron/welcome.php'; } And the form: <table width="90%" cellspacing="0" cellpadding="0"> <tr> <td width="50%">Username:</td> <td width="50%"><input type="text" id="username" /></td> </tr> <tr> <td width="50%">Password:</td> <td width="50%"><input type="password" id="password" /></td> </tr> </table> I am using jquery for the submit, but it's not the jquery giving the problems, it's the AJAX. any advice? Should "get" be "post" maybe?! Not sure.
-
Is it a global message? Meaning is it viewable to more than 1 person? E.g. If I personal mail you, and you read it, it goes from "unread" to "read". OR Is it like user 1 viewed it, they see "read" but user 2 hasn't so they see "unread" ? well if it's the 2nd one... easy. user_viewed (table name) id (auto) uid (user who is viewing) type (viewing a message or item) typeid (message or item id being viewed) When they view the page make sure you update it: $item_viewed = mysql_query("SELECT * FROM `user_viewed` WHERE uid='$uid', type='item', typeid='$item_id'"); $message_viewed = mysql_query("SELECT * FROM `user_viewed` WHERE uid='$uid', type='message', typeid='$msg_id'"); if(mysql_num_rows($item_viewed) < 1){ mysql_query("INSERT INTO `user_viewed`(uid, type, typeid) VALUES ('$uid', 'item', '$item_id')"); } if(mysql_num_rows($item_viewed) < 1){ mysql_query("INSERT INTO `user_viewed`(uid, type, typeid) VALUES ('$uid', 'message', '$msg_id')"); } Now on the page to echo Read or Unread... here is the code snippet. (if on same page as sql update, combine the two...) $item_viewed = mysql_query("SELECT * FROM `user_viewed` WHERE uid='$uid', type='item', typeid='$item_id'"); $message_viewed = mysql_query("SELECT * FROM `user_viewed` WHERE uid='$uid', type='message', typeid='$msg_id'"); if(mysql_num_rows($message_viewed) < 1){ echo 'Message Unread'; }else{ echo 'Message Read'; } if(mysql_num_rows($item_viewed) < 1){ echo 'Item Unread'; }else{ echo 'Item Read'; } And if you want it to go back to unread to all users when the message or item is updated... simply add this code to the updating code: mysql_query("DELETE FROM `user_viewed` WHERE type='message' AND typeid='$msg_id'"); mysql_query("DELETE FROM `user_viewed` WHERE type='item' AND typeid='$item_id'"); And now you can use the same table for multiple things, rather than just the "forum messages". If that makes sense.
-
I think viewing all of the HTML would give more of general idea of what's happening... =)
-
Or when a user requests their password, make them verify username & e-mail address and reset their password, mail them the new one (before md5() is in place) then md5() the password and insert it into the database. =) Easy as 1... 2... 3... That's what I do!
-
Yeah what oni-kun said... Timestamps are much more easier to use and much cleaner and easier to "return" in any format you please!
-
Not to sound, mean, but I use that exact code for my boards on my website. e.g. You posting a reply on here, you hit enter button, it supplies a "<br>"... And it works for every browser, not just some... Which is why I use it...
-
Try this... as an alternative. Generally nl2br() is the correct term. <?php $news = "This is my news. Hey there! Thanks buddy! =) Hi!"; $news = str_replace(" ", "<br />", $news); echo $news; // Should return the "news" with line breaks. ?> OR <?php $news = "This is my news. Hey there! Thanks Buddy! =) Hi!"; echo nl2br($news); // Should print it perfectly fine the way you want it. ?>
-
I use both depending on the situations. When retrieving data from my database, and I am inserting them into a table, I simply use the breaks. However, if I am coding something other than that, I continue with an "echo".
-
http://havenpets.tridiantgames.com/test/jstest.php - Example It's working fine on Firefox, Internet Explorer and Google Chrome... Take a look for yourself.
-
Whoops sorry, I forgot IE is a little fussy. Works more than a charm now <script> function sub_total(){ var qty = document.getElementById('quantity').value; if(!qty){ var qty = 0; } var price = document.getElementById('price').value; if(!price){ var price = 0; } document.getElementById('sub_total').value = qty * price; } </script> <input name="quantity" id="quantity" size="35" maxlength="255" onkeyup="sub_total();" /> <input name="price" id="price" size="35" maxlength="255" onkeyup="sub_total();" /> <input name="sub_total" id="sub_total" size="35" maxlength="255" />
-
<script> function sub_total(){ qty = document.getElementById('quantity').value; if(!qty){ qty = 0; } price = document.getElementById('price').value; if(!price){ price = 0; } document.getElementById('sub_total').value = qty * price; } </script> <input name="quantity" id="quantity" size="35" maxlength="255" onkeyup="sub_total();" /> <input name="price" id="price" size="35" maxlength="255" onkeyup="sub_total();" /> <input name="sub_total" id="sub_total" size="35" maxlength="255" /> Works like a charm. Enjoy