•
•
•
•
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
![]() |
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?
Thanks,
Max
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
Price Beater Promise
10% Cheaper Hosting, & Double Bandwidth and Web Space
Click here to apply
•
•
Join Date: Jun 2008
Location: Phoenix, AZ
Posts: 534
Reputation:
Rep Power: 2
Solved Threads: 50
Someone will probably blow me away with some regular expression but this is what I would do for the domain extension:
And then just use the same
javascript Syntax (Toggle Plain Text)
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /> <title>Untitled Document</title> <script language="javascript" type="text/javascript"> function getExtension() { var domainname = document.getElementById('txtDomain').value; var extensions = new Array(".com", ".co.uk", ".net", ".org"); //add other desired extensions for(i = 0; i < extensions.length; i++) { if(domainname.substr(domainname.length - extensions[i].length, extensions[i].length) == extensions[i]) { document.getElementById('txtExtension').value = extensions[i]; } } } </script> </head> <body onLoad="getExtension('daniweb.com');"> <input type="text" id="txtDomain" name="txtDomain" onBlur="getExtension('txtDomain');" /> <input type="text" id="txtExtension" name="txtExtension" /> </body> </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
![]() |
•
•
•
•
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
•
•
•
•
•
•
•
•
DaniWeb JavaScript / DHTML / AJAX Marketplace
- Help me please. (PHP)
- Programming FAQ - Updated 1/March/2005 (Computer Science and Software Design)
- Array Sorting on a User Supplied Element (Java)
- Getting funky errors with a simple for loop, anyone care to help? (JavaScript / DHTML / AJAX)
- Warning: mysql_num_rows(): (PHP)
- I just can't get this Javascript (JavaScript / DHTML / AJAX)
Other Threads in the JavaScript / DHTML / AJAX Forum
- Previous Thread: Onchange
- Next Thread: Javascript is not working on Firefox


Linear Mode