473,748 Members | 5,849 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

adding http:// to website in form

Is there a way when a user fills out a form and it asks them to enter
a website that it'll be reformatted with http:// in front of it if it
isn't already there. i.e. domain.com would become http://domain.com
but http://example.com would be left alone.

tia,
Chris
Jan 20 '08 #1
7 1608
Chris wrote on 20 jan 2008 in comp.lang.javas cript:
Is there a way when a user fills out a form and it asks them to enter
a website that it'll be reformatted with http:// in front of it if it
isn't already there. i.e. domain.com would become http://domain.com
but http://example.com would be left alone.
Yes.

Use Javascript.

--
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)
Jan 20 '08 #2
Chris said the following on 1/20/2008 2:06 PM:
Is there a way when a user fills out a form and it asks them to enter
a website that it'll be reformatted with http:// in front of it if it
isn't already there. i.e. domain.com would become http://domain.com
but http://example.com would be left alone.
If the data is being submitted to the server, then you need to do it on
the server if you want it to be reliable.

Client-side, it could be as simple as reading the first 7 characters of
the value of the input. There are other ways as well using Regular
Expressions and even indexOf.

var firstSeven = fieldRef.substr ing(0,7)
if (firstSeven != "http://"){
fieldRef.value = "http://" + fieldRef.value
}

One thing you didn't answer is what happens if the value starts with
https://, ftp:// or any other valid protocol?

--
Randy
Chance Favors The Prepared Mind
comp.lang.javas cript FAQ - http://jibbering.com/faq/index.html
Javascript Best Practices - http://www.JavascriptToolbox.com/bestpractices/
Jan 20 '08 #3
VK
On Jan 20, 10:06 pm, Chris <chris95...@yah oo.comwrote:
Is there a way when a user fills out a form and it asks them to enter
a website that it'll be reformatted with http:// in front of it if it
isn't already there. i.e. domain.com would becomehttp://domain.com
buthttp://example.comwoul d be left alone.
If you have a guarantee that all resources will be for http protocol
exclusively and not for http or https or ftp or news etc. Otherwise
this helper becomes a great annoyance.

<input type="text" name="URL" onblur="
if (this.value.ind exOf('http://') != 0) {
this.value = 'http://' + this.value;
}">

but really what you _should_ do is to simply pre-fill the input with
http://
<input type="text" name="URL" value="http://">

If visitor has http resource to share then she will appreciate your
care. If it's another type of resource then user will simply delete
the helper and type/paste whatever is really needed.
Jan 20 '08 #4
VK
On Jan 20, 10:27 pm, Thomas 'PointedEars' Lahn <PointedE...@we b.de>
wrote:
Chris wrote:
Is there a way when a user fills out a form and it asks them to enter
a website that it'll be reformatted with http:// in front of it if it
isn't already there. i.e. domain.com would becomehttp://domain.com
buthttp://example.comwoul d be left alone.

Yes, there is.
Net result of this thread: two a** h***s against two men :-)
Jan 20 '08 #5
On 20 ñÎ, 21:37, VK <schools_r...@y ahoo.comwrote:
On Jan 20, 10:27 pm, Thomas 'PointedEars' Lahn <PointedE...@we b.de>
wrote:
Chris wrote:
Is there a way when a user fills out a form and it asks them to enter
a website that it'll be reformatted with http:// in front of it if it
isn't already there. i.e. domain.com would becomehttp://domain.com
buthttp://example.comwoul dbe left alone.
Yes, there is.

Net result of this thread: two a** h***s against two men :-)
Solution with regular expression:
function formatValue(aSt ring)
{
return aString.replace (/^(?:(?!http:\/\/).)+/i,"http://"+aString);
}
Jan 21 '08 #6
Georgi Naumov wrote on 21 jan 2008 in comp.lang.javas cript:
On 20 ñÎ, 21:37, VK <schools_r...@y ahoo.comwrote:
>On Jan 20, 10:27 pm, Thomas 'PointedEars' Lahn <PointedE...@we b.de>
wrote:
Chris wrote:
Is there a way when a user fills out a form and it asks them to
enter a website that it'll be reformatted with http:// in front
of it if it isn't already there. i.e. domain.com would
becomehttp://domain.com buthttp://example.comwoul dbe left alone.
Yes, there is.

Net result of this thread: two a** h***s against two men :-)
???
Solution with regular expression:
function formatValue(aSt ring)
{
return
aString.replace (/^(?:(?!http:\/\/).)+/i,"http://"+a
String);
}
Shorter and more comptible with older versions:

function formatValue(aSt ring) {
return aString.replace (/^(http:\/\/)?/i,"http://");
};
--
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)
Jan 21 '08 #7
On Jan 20, 2:34*pm, VK <schools_r...@y ahoo.comwrote:
On Jan 20, 10:06 pm, Chris <chris95...@yah oo.comwrote:
Is there a way when a user fills out a form and it asks them to enter
a website that it'll be reformatted with http:// in front of it if it
isn't already there. *i.e. domain.com would becomehttp://domain.com
buthttp://example.comwoul dbe left alone.

If you have a guarantee that all resources will be for http protocol
exclusively and not for http or https or ftp or news etc. Otherwise
this helper becomes a great annoyance.
Well put.
>
<input type="text" name="URL" onblur="
*if (this.value.ind exOf('http://') != 0) {
* this.value = 'http://' + this.value;
*}">
This is silly. Tabbing through an empty field will populate it with
"http://". What if the user wanted to leave it blank? What if they
enter "No protocol" and hit enter? Or perhaps there is a leading
space.

If the OP has no way to validate on the server (which would be
unfortunate as you cannot rely on script), then the only proper
solution is to validate the input on submit (and possibly add the
protocol without bothering the user.) If the OP can validate on the
server, then the server can add the protocol at that point.

Jan 21 '08 #8

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

44
3256
by: Mike | last post by:
I'm used to unix/cgi scripts so im slightly out of my depth here. Ive got an asp script for a website form which works fine. What i want to do is also get the form to include the ip address of the perosn sending the form ie <input type=hidden name=env_report value=REMOTE_ADDR> Anyone know how to apply this to this asp script below?: <%
4
5899
by: OJ | last post by:
Hi, This works to maximize the window, but wants to load yahoo locally : C:\WINDOWS\Desktop\www.yahoo.com <html> <script type="text/javaScript"> <!-- function test() { qwe = window.open("www.yahoo.com","");
3
2624
by: Nik | last post by:
Hi everyone, Is there anyway of letting the user click on a link or image, and saving a shortcut icon to the users desktop? Thanks Nik
1
1308
by: ECathell | last post by:
I am getting an unspecified error when adding a windows form to a project. New project, old project. Doesn't matter. Also happens for user control. All the message box says is Unspecified Error. -- --Eric Cathell, MCSA
6
1321
by: Beany | last post by:
i need help!!!!!!! Has any1 got examples of the following that i can view: 1) simple form field Validations 2) Adding to a database using a form with a adding button ??????
2
9828
by: fniles | last post by:
In VB.Net 2003 how can I download a file from an HTTP website ? For example, I need to download file abc.zip from http://mydata.com/mycompany. Thank you.
2
1116
by: Kusank | last post by:
Hi, I don't know anything about php... I was wondering if anyone knew a website or something that i could go to for help on making the form in my website send to the website's email address.
2
1372
by: dan07 | last post by:
Language used: Javascript Application using iFrame: Microsoft CRM 3.0 form Is there a generic way for an iFrame to send a variable to a remote website form? I need to be able to open up the results of this remote form in a iFrame. Any help would be appreciated.
1
1132
by: VAIO PC | last post by:
http://dcaic.com/alta_google.htm
0
8984
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8823
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9530
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9363
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9312
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
1
6793
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4864
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3300
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2775
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.