Input Field Substitution - II

Posted on 2003-12-09
Last Modified: 2010-05-18
This week "mikosha" gave me this code below. It adds host "srv" to the domain name typed in an Input Field, hiddening this operation. It works nicely.

But, right now I found out that, whenever the data entered at the Input Field contains an hifen ( - ) it doesn't work. For instance, if I type a Server Name like "", it doesn't work.

If "mikosha" reads it I think he will fix quickly, but if someone else can help me I thank a lot in advance.


<input name="SERVER">
<input name="SERVER_UPD" type='hidden'>
<input type=button value=Replace onClick="mybutton_click(this.form)">
<script language='javascript'>
function mybutton_click(current_form){
   current_form .SERVER_UPD.value = this.form.SERVER.value.replace(/^(mail.|www.|srv.)*(\w+\.\w+)/i,'srv.$2');
   return true
Question by:multisites
  • 3
LVL 11

Accepted Solution

Zontar earned 125 total points
ID: 9904083
current_form.SERVER_UPD.value = current_form.SERVER.value.replace(/^[mail|www]\.([\w|\-]+\.\w+)/i,'srv.$1');

Author Comment

ID: 9904271
Hhmm, Zontar, unhapilly it didn't work. I don't know if it has any sintax error. In order to make it easy to verify, I tried your code on this code, which doesn't hide the field.

The former code:

<input name="SERVER">
<input type=button value=Replace onClick="this.form.SERVER.value=this.form.SERVER.value.replace(/^(mail.|www.|srv.)*(\w+\.\w+)/i,'srv.$2')">

Your new code:

<input name="SERVER">
<input type=button value=Replace onClick="this.form.SERVER.value=this.form.SERVER.value.replace(/^[mail|www|srv]\.([\w|\-]+\.\w+)/i,'srv.$1')">

Thanks for helping.

Expert Comment

ID: 9904738
Just appears to be a small typo  on Zontar's code offering.  Try this instead:

<input type=button value=Replace onClick="this.form.SERVER.value=this.form.SERVER.value.replace(/^[mail|www|srv]\.([\w|\-]+\.\w+)/i,'srv.$2')">


Author Comment

ID: 9905515

The typo you mentioned was just changing $1 to $2 right? Well, sorry, it doesn't work. Thanks for further helping.


Author Comment

ID: 9906114
Wow, after many attempts I got the right syntax. See:

<input name="SERVER">
<input type=button value=Replace onClick="this.form.SERVER.value=this.form.SERVER.value.replace(/^(mail.|www.|srv.)*(\w+\.\w+|\w+\-\w+)/i,'srv.$2')">

Anyway, thanks a lot. Please, could the admin close this question?


Featured Post

Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Format results with PHP 3 75
Using YubiKey with REST API application 2 117
Lines Not Lining Up 2 70
Create and populate iFrame onClick of a button? 1 79
Article by: Matthew
I am a very big proponent of technology compliance standards and strive to meet such criteria in all of my work. That includes my site, which is 100% XHTML 1.0 compliant as determined by the World Wide Web Consortium. https://www.matthewstevenkel…
Browsers only know CSS so your awesome SASS code needs to be translated into normal CSS. Here I'll try to explain what you should aim for in order to take full advantage of SASS.
Viewers will learn about if statements in Java and their use The if statement: The condition required to create an if statement: Variations of if statements: An example using if statements:
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…

773 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question