User Name Password Register
DaniWeb IT Discussion Community
All
What is DaniWeb IT Discussion Community?
You're currently browsing the JavaScript / DHTML / AJAX section within the Web Development category of DaniWeb, a massive community of 391,922 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 3,704 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our JavaScript / DHTML / AJAX advertiser: Lunarpages Web Hosting
Views: 247 | Replies: 1
Reply
Join Date: Oct 2006
Location: UK
Posts: 136
Reputation: MaxMumford is an unknown quantity at this point 
Rep Power: 2
Solved Threads: 0
MaxMumford's Avatar
MaxMumford MaxMumford is offline Offline
Junior Poster

simple javascript syntax errors

  #1  
Jul 13th, 2008
Hey,

Simple javascript problem:

user enters desired domain name into "domain" field and submits, php scripts check if domain is available. If it is, a paypal add to basket button is written onto the page, however i cannot use php to get the content of the "domain" field and put it into hidden fields of the paypal button for various reasons so instead I need to use javascript. Also i want to search what the user entered to find out what kind of domain suffix they typed (.co.uk, .com etc) and write a variable with a corresponding price. I have VERY little experience with javascript and am only really able to code what is below from knowledge of php and tutorials but the script isnt working. any ideas?

var domain = document.getElementById("domain").value;

var domainsuffix1 = (domain.search(/.com/i));
if (var domainsuffix1 > 0) {var domainsuffix = "£5";};

Thanks,


Max
Economizerz Hosting
Price Beater Promise

10% Cheaper Hosting, & Double Bandwidth and Web Space
Click here to apply
AddThis Social Bookmark Button
Reply With Quote  
Join Date: Jun 2008
Location: Phoenix, AZ
Posts: 534
Reputation: R0bb0b is on a distinguished road 
Rep Power: 2
Solved Threads: 50
R0bb0b's Avatar
R0bb0b R0bb0b is offline Offline
Posting Pro

Re: simple javascript syntax errors

  #2  
Jul 13th, 2008
Someone will probably blow me away with some regular expression but this is what I would do for the domain extension:
  1. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  2. <html xmlns="http://www.w3.org/1999/xhtml">
  3. <head>
  4. <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
  5. <title>Untitled Document</title>
  6. <script language="javascript" type="text/javascript">
  7. function getExtension()
  8. {
  9. var domainname = document.getElementById('txtDomain').value;
  10. var extensions = new Array(".com", ".co.uk", ".net", ".org"); //add other desired extensions
  11.  
  12. for(i = 0; i < extensions.length; i++)
  13. {
  14. if(domainname.substr(domainname.length - extensions[i].length, extensions[i].length) == extensions[i])
  15. {
  16. document.getElementById('txtExtension').value = extensions[i];
  17. }
  18. }
  19. }
  20. </script>
  21. </head>
  22.  
  23. <body onLoad="getExtension('daniweb.com');">
  24. <input type="text" id="txtDomain" name="txtDomain" onBlur="getExtension('txtDomain');" />
  25. <input type="text" id="txtExtension" name="txtExtension" />
  26. </body>
  27. </html>

And then just use the same
document.getElementById('txtDomain').value = 'desired value'; idea for populating the domain text field
Last edited by R0bb0b : Jul 13th, 2008 at 10:31 pm.
“Be who you are and say what you feel because those who mind don't matter and those who matter don't mind.” - Dr. Seuss
Reply With Quote  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 

DaniWeb JavaScript / DHTML / AJAX Marketplace
Thread Tools Display Modes

Similar Threads
Other Threads in the JavaScript / DHTML / AJAX Forum

All times are GMT -4. The time now is 8:16 am.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC