Jump to content


.josh

Member Since 31 Dec 1969
Offline Last Active Today, 03:04 PM

#1429656 html form javascript validation: checking multiple fields entered is equal to...

Posted by .josh on 11 May 2013 - 08:25 PM

<form name="htmlform" enctype="multipart/form-data" method="post" action="base_submit_form.php" onsubmit="return validateForm(this);"
 onreset="return confirm('Are you sure that you want to reset this form?');">


<label for="submit_username">Username (max length 15): </label>
<input  type="text" name="submit_username" maxlength="15" size="30"><br />
<br />
Number of Each Rooms:<br />
<input  type="number" name="livingrooms" min="0" max="10" maxlength="2" size="1">Living Rooms<br />
<input  type="number" name="diningrooms" min="0" max="10" maxlength="2" size="1">Dining Rooms<br />
<input  type="number" name="kitchens" min="0" max="10" maxlength="2" size="1">Kitchens<br />
<input  type="number" name="bedrooms" min="0" max="10" maxlength="2" size="1">Bedrooms<br />


<input type="submit" value="Submit">&nbsp;&nbsp;<input type="reset" value="Reset!">
</form>
<script type='text/javascript'>
function validateForm(formElement) {
  /* validate username */
  var username = formElement.elements['submit_username'];
  if( username.value == "" ) {
    alert( "Please Enter a Username." );
    username.focus();
    return false;
  }
  /* validate number of rooms */
  var rooms = ['livingrooms','diningrooms','kitchens','bedrooms']; 
  var roomElements = formElement.elements;
  var total = 0;
  for (var r=0,rl=rooms.length;r<rl;r++) {
    total += +roomElements[rooms[r]].value;
  }
  if (total>=0 && total<=12) {
    return true;
  } else {
    alert('Total amount of rooms must be between 0 and 12'); 
    return false;
  }
}
</script>

 

 

Some notes about the code you already had:

  • You misspelled your bedrooms input field (you had 'beedrooms' not 'bedrooms').  Well I assume that's a typo so I changed it
  • You were passing a reference this to your function but weren't actually making use of it, so I altered your username logic to use it
  • Your username input field had a required attribute in it.  This is a built-in way to make sure the input field is not empty and is fine..except that you turn around and attempt to validate it in your function.  Well when you have both, your custom error msg alert will never execute, because the required attribute will be evaluated first.  So the only way it will even make it to your function is if it's already filled out, so your condition for username will never evaluate true.  So to make a long story short, pick one or the other.  I updated the code to remove the required attribute under the assumption that you wanted a custom validation and error msg.



#1426851 Username change/login issues.

Posted by .josh on 27 April 2013 - 09:45 AM

yes, it's definitely the cockies.




#1426716 Username change/login issues.

Posted by .josh on 26 April 2013 - 08:15 AM

Dragosvr92 I think your frustration is directed at the wrong people.  We are not developers for IPB, we simply use their product, same as thousands of other sites out there.  We have no more leverage or weight in asking for a change than you or anybody else.  You may think that we do if we show up as "the phpreaks community" vs "me, an individual" but we don't.  We've tried.  We've even had some members of our staff work as members of their staff, a "person on the inside" if you will, and even then they had little to no more leverage/weight in bringing up issues.  Their core dev team does their thing and that's pretty much the end of it.  

 

So if you want your suggestion considered or implemented, march yourself over to the IPB community and post your thoughts there.  Good luck with that endeavor, given what I just said, but you are certainly barking up the wrong tree arguing with us about it. 




#1422776 How To Get Into Web Development?

Posted by .josh on 03 April 2013 - 06:47 PM

sarchasm ftw




#1422645 How To Get Into Web Development?

Posted by .josh on 03 April 2013 - 08:27 AM

So you've spent a couple months learning the basics? Congrats, you are now just as (if not more) qualified as most of the devs our there pretending to be professionals. All you have to do now is learn how to lie on a resume and talk a good game.


#1409255 Would you find something like this useful?

Posted by .josh on 30 January 2013 - 06:44 PM

So it sounds/looks basically like what most IDE "auto-complete" features do.  Not sayin' it's a bad idea, just saying it seems more like reinventing the wheel, not really seeing anything new or different from this.  IOW between auto-completes from site search boxes or IDEs...this is kinda already covered...

Also, it's only really useful as a quick guide for people who already know what they are looking for but fail at remembering details like argument orders.  If someone knows there is probably a function out there that does what they want but can't quite describe it, they are likely going to be entering into a search bar a description of what they are trying to do.  That makes the rest of the search results returned more useful.


sidenote:  I like auto-complete suggestion dropdowns for search boxes but fuck all i fucking HATE code auto-completers... I know a lot of people like it, especially since the "popups" do usually show syntax and descriptions etc.. but for me...it ends up hurting more than helping.  Like for instance I use html-kit and I can't tell you how many times I've gone to make an opening php tag only to have html-kit decide I wanted an html p tag.  /me shakes angry fist at auto-complete.


#1409079 JavaScript Formatting and SEO

Posted by .josh on 29 January 2013 - 08:56 PM

I don't understand why you would need to write the formatter in both php AND js to begin with?  Whether you decide to do it with php (good idea) or js (bad idea), you should only be having to do it once...can you explain why you think you would need to do it in both places?

Anyways, using js to format your data is a bad idea, and it will most certainly hurt your SEO efforts, for all the reasons already given.


#1409077 Would you find something like this useful?

Posted by .josh on 29 January 2013 - 08:51 PM

Also, I disagree with your statement about how php doc can be better...how much experience do you have sorting through manuals? php is by miles one of the most well organized, clear, easily navigated documents out there, complete with useful examples and tons of useful comments in the entries, even before they implemented a rating system.  It is second to none..


#1409076 Would you find something like this useful?

Posted by .josh on 29 January 2013 - 08:49 PM

Maybe i'm missing something, but it sounds to me like you are just wanting to make a standard site search box?


#1408833 basic php form that posts to itself

Posted by .josh on 28 January 2013 - 04:32 PM

You need to have a condition to check if the form was submitted. You can check with $_POST['textFieldNameHere'].  If it exists, call your function, passing the value of the posted variable, and echo the results. Then after that (outside of the condition), you need to echo out the html code for the form with the input field (and a name attribute matching what your condition looks for), and submit button. The form method should be POST and the action should be left blank, or else the URL of the script.


#1408821 error with onunload event

Posted by .josh on 28 January 2013 - 02:27 PM

See my previous post listing the reasons you may still not see it... the bottom line is that these functions are not part of the standard js specification, and even if they are built into a browser, different browsers may or may not block it, or certain things within it.  

Add something else in your function like a simple console.log("goobye!").  Open up your javascript console in Chrome.  Refresh the page. You will see that your goodbye function is being called.  You will see that the console.log call works. And you will see a message in the console telling you that Chrome specifically blocked the alert call. 

There isn't really anything you can do about this stuff.  The bottom line is that when it comes to performing an action before the page is unloaded, there is no reliable cross-browser method.  And even for what does work, it is limited, because people do not like it when sites do stupid things like popup "are you sure you want to leave?" messages and the like.  Even if you have legitimate operations to perform before a visitor leaves (eg: deleting a logged in session cookie, etc..), the "annoying popup" sites kinda ruined it for everybody.  

So basically what I'm advising here is to just forget about coding something for the unload event.  There are other ways to go about whatever it is you need to do, and if what you "need to do" is display some annoying "don't leave!" message, absolutely nobody likes that sort of thing, and it's a guaranteed way to make sure people never return to your site. 


#1408793 error with onunload event

Posted by .josh on 28 January 2013 - 11:48 AM

hmm okay, well here are some possible reasons it's not working:

- you are using a browser that doesn't have .onunload (it is not a standard)
- I noticed specifically that the function is being called on unload, but alert is being blocked in my current version of FF and Chrome.

You could try using .onbeforeunload instead...

window.onbeforeunload = goodbye;



#1408756 error with onunload event

Posted by .josh on 28 January 2013 - 09:04 AM

So you tried changing this:

window.onunload = goodbye();

to this?

window.onunload = goodbye;

notice the lack of () after the goodbye.  

p.s. - my username is .josh and the "advanced member's" username is nogray.  Our usernames are in the light blue header of each post, same as where it shows your name!


#1408571 error with onunload event

Posted by .josh on 27 January 2013 - 02:49 PM

so are you saying you get that "Thank you for visiting. come back soon!" message when your page first loads?


#1408312 3.3m USD to build a website: what are your thoughts?

Posted by .josh on 25 January 2013 - 08:01 PM

$100/hr is pretty damn cheap for an agency to be charging...I doubt many do, except for possibly a super small company of like 5 people... I would expect an enterprise level agency to be charging more like $250-$300/hr minimum.  I don't really get involved in the money end of things at my job but I've seen a few SOWs of ours and from 3rd party agencies for clients we've worked together with, and that's what I've seen...




Cheap Linux VPS from $5
SSD Storage, 30 day Guarantee
1 TB of BW, 100% Network Uptime

AlphaBit.com