paulmo Posted January 25, 2009 Share Posted January 25, 2009 this used to work for me. at a loss; thanks for help. <script type="text/javascript">var FormName = "myform";var FieldName = "name";var FieldName = "message";function CapitalizeNames() {var ValueString = new String();eval('ValueString=document.'+FormName+'.'+FieldName+'.value');ValueString = ValueString.replace(/ +/g,' ');var names = ValueString.split(' ');for(var i = 0; i < names.length; i++) { if(names[i].length > 1) { names[i] = names[i].toLowerCase(); letters = names[i].split(''); letters[0] = letters[0].toUpperCase(); names[i] = letters.join(''); } else { names[i] = names[i].toUpperCase(); } }ValueString = names.join(' ');eval('document.'+FormName+'.'+FieldName+'.value=ValueString');return true;}</script></head><div id="col1"><div style="background-color:#FFFFFF; padding:10px" class="rounded {10px}"><p><form name="myform" method="post" action="beta.php"> //post to same page<p>First Name: <input type="text" name="name" class="buttonsb"/></p<center>Write something: </br></br><input type="text" name="message" class="buttonsb"/> <input type="hidden" name="searching" value="yes" /></br></br></br><input type="submit" value="Process" class="buttons" onclick="return CapitalizeNames()"></center></form> Link to comment Share on other sites More sharing options...
Ingolme Posted January 25, 2009 Share Posted January 25, 2009 Hmm, this code isn't really efficient and has a few problems:1. You're declaring the same variable twice. This will give an error because the variable is already declared, aside from that, if it didn't give an error, you'd be changing the value of the variable. var FieldName = "name";var FieldName = "message"; 2. Instead of using eval(), use the better methods to access elements: getElementById().3. I could fix your Javascript for you, but I actually recommend that you do this on the server side, since users can turn off Javascript. So I'll give you a PHP solution instead.Here's what you should do in beta.php $name = $_POST['name'];$message = $_POST['message'];$name = ucfirst($name);$message = ucfirst($message); Link to comment Share on other sites More sharing options...
jeffman Posted January 25, 2009 Share Posted January 25, 2009 Since $name might hold multiple names (as I understand the code), ucwords($name) would work better. Link to comment Share on other sites More sharing options...
paulmo Posted January 25, 2009 Author Share Posted January 25, 2009 yes! thanks for that! is this in the php manual? if so i missed it. i'm also trying full text search from text form input for any word(s) (question posted on php forum), and been reading about regex. any direction or links to reading appreciated.have read peachpit press' books on php and javascript; seems so many tasks can be covered by both. but i'd rather use php when possible so thanks a lot for this! Link to comment Share on other sites More sharing options...
jeffman Posted January 25, 2009 Share Posted January 25, 2009 This is a decent intro. http://gnosis.cx/publish/programming/regul...xpressions.htmlThere's a lot of intro stuff. The lessons begin at Matching Patterns in Text: The Basics Link to comment Share on other sites More sharing options...
paulmo Posted January 26, 2009 Author Share Posted January 26, 2009 thanks. regular expressions and/or text functions...a lot to learn. Link to comment Share on other sites More sharing options...
jeffman Posted January 26, 2009 Share Posted January 26, 2009 In a way, Regular Expressions are a language of their own. It can take years of steady practice to really know what you're doing. Fortunately, simple matches are easy to construct, and you can increase complexity as time and needs require. In that way, it's not like a language, where you have to learn a whole bunch just to get started. Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.