Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win


Input Field Substitution - II

Posted on 2003-12-09
Medium Priority
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 "abc-company.com", 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
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
LVL 11

Accepted Solution

Zontar earned 250 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

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

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

Preface In the first article: A Better Website Login System (http://www.experts-exchange.com/A_2902.html) I introduced the EE Collaborative Login System and its intended purpose. In this article I will discuss some of the design consideratio…
Introduction Knockoutjs (Knockout) is a JavaScript framework (Model View ViewModel or MVVM framework).   The main ideology behind Knockout is to control from JavaScript how a page looks whilst creating an engaging user experience in the least …
Viewers will learn about arithmetic and Boolean expressions in Java and the logical operators used to create Boolean expressions. We will cover the symbols used for arithmetic expressions and define each logical operator and how to use them in Boole…
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.

618 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