Jump to content

Spaces in Javascript popup


The Praetorian

Recommended Posts

Okay, my second question is, will all of that still work so far as the php is concerned?
You shouldn't rely on javascript to perform the validation, if the user has it turned off then it'll cause problems.Your priority should be to validate all the info with php, javascript should only used to reduce the amount of requests going to the server by performing client side validation, think of it a luxury.
Link to comment
Share on other sites

I don't know how to use php for required fields... I did a search and the javascript was the first one that I found. It's not that big a deal anyway. I prefer to just have it there for those that have JS on, and for those that don't they won't notice anyway. My question still stands though. Is there any way to add the space to the pop-up message without messing up the whole process?

Link to comment
Share on other sites

I don't know how to use php for required fields... I did a search and the javascript was the first one that I found. It's not that big a deal anyway. I prefer to just have it there for those that have JS on, and for those that don't they won't notice anyway. My question still stands though. Is there any way to add the space to the pop-up message without messing up the whole process?
What is it your trying to do, put a space between the name value pair?If so then you don't add the space onto the end of the name as it will cause problems, what i would do is just add the space dynamically,
var space=" "; //there should be a large space between the quotes herevar fieldValue="name of element"+space+document.getElementById('blah').value;alert(fieldValue);
Something along those lines maybe? :)
Link to comment
Share on other sites

Not really.As I have it now, when someone tries to hit "send" without filling out required fields, a javascript pop-up displays that tells them which fields they haven't filled out, by listing the name of each fields id. However, for the id's that have more than one word, they display without a space ( CharacterInformation ) in the popup. I want to add a space to how they display. But when I try to add a space in the javascript, it no longer works. Adding a space in the javascript as well as the php also doesn't work.Would it help if I pasted the php I'm using?

Link to comment
Share on other sites

Here's the php. I realize this isn't the php that matches the javascript I gave above, but this is the shorter one. Everything is the same for this file's javascript except for the name of the form and the listed form elements.

<?phpif (isset($_REQUEST['Your Email'])){$YourName = $_REQUEST['Name'];$YourEmail = $_REQUEST['Email'];$YourMessage = $_REQUEST['Message'];mail( "author@tsrealms.com", "Subject: $Email","$Message","From: $Email" );echo "<h1>Thank you for your message! One of the admins should be getting back to you via email within 24 hours.</h1>";}else{echo "<form method='post' action='mail.php' name='mail' onsubmit='return ValidateRequiredFields();'><center><p>* : Required Fields</p><p><b>Name *</b><br /><input type='text' name='Name' size='20' /></p><p><b>Email *</b><br /><input type='text' name='Email' size='20' /></p><p><b>Message *</b><br /><textarea name='Message' rows='15' cols='52'></textarea></p><p><input type='submit' value='Send' /></p></center></form>";}?>

Link to comment
Share on other sites

Here's the php. I realize this isn't the php that matches the javascript I gave above, but this is the shorter one. Everything is the same for this file's javascript except for the name of the form and the listed form elements.
Hey sorry i never realised you had posted the js above, i just had a look at it and is this what your after?
<!-- Copyright 2005 Bontrager Connection, LLC//// Two places need to be customized.////// Place 1:// Between the quotation marks, specify the name of //    your form.var FormName = "app";// Place 2:// Between the quotation marks, specify the field names //    that are required. List the field name separated //    with a comma.var RequiredFields = "CharacterName,CharacterAge,History,WritingSample,Email";//// No other customization of this JavaScript is required.///////////////////////////////////////////////////////////function ValidateRequiredFields(){var FieldList = RequiredFields.split(",")var BadList = new Array();for(var i = 0; i < FieldList.length; i++) {	var s = eval('document.' + FormName + '.' + FieldList[i] + '.value');	s = StripSpacesFromEnds(s);	if(s.length < 1) { BadList.push(FieldList[i]); }	}if(BadList.length < 1) { return true; }var ess = new String();if(BadList.length > 1) { ess = 's'; }var message = new String('\n\nThe following field' + ess + ' are required:\n');for(var i = 0; i < BadList.length; i++){  if (BadList[i] == "CharacterName"){BadList[i] = "Character Name";}  if (BadList[i] == "CharacterAge"){BadList[i] = "Character Age";}  if (BadList[i] == "WritingSample"){BadList[i] = "Writing Sample";}message += '\n' + BadList[i];}alert(message);return false;}function StripSpacesFromEnds(s){while((s.indexOf(' ',0) == 0) && (s.length> 1)) {	s = s.substring(1,s.length);	}while((s.lastIndexOf(' ') == (s.length - 1)) && (s.length> 1)) {	s = s.substring(0,(s.length - 1));	}if((s.indexOf(' ',0) == 0) && (s.length == 1)) { s = ''; }return s;}// -->

bascially i added this before the alert, if the array equals the condition then stick a space in the middle, i've not tested it with the php but it should work fine as your dynamically changing the values. :)

if (BadList == "CharacterName"){BadList = "Character Name";} if (BadList == "CharacterAge"){BadList = "Character Age";} if (BadList == "WritingSample"){BadList = "Writing Sample";}
Link to comment
Share on other sites

Hm. That didn't work either. No errors, but the pop-up still didn't have spaces. Also, down at the bottom of the list of required fields was an extra one that just said "undefined".
Are you sure you copied it over correctly? It was just a straight swap, one external js for another.http://scott100.atspace.com/The%20Shattere...Application.htmScreen Dumppicvr3.th.png
Link to comment
Share on other sites

  • 2 weeks later...

Hi. I'm using vb.net wndows application, along with javascript for the validations , write to EMAILID if u r cecking in email idthis types of message to delever to usera)(.) dot is missingB)two @ are not acceptingc) last dot after use(.com (or) co.in(or).in(or).net (or).org (or).uk and etc...please any one known give me reply

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...