• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 169
  • Last Modified:

Input Field Substitution - II

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.

Mario./

<form>    
<input name="SERVER">
<input name="SERVER_UPD" type='hidden'>
<input type=button value=Replace onClick="mybutton_click(this.form)">
</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
}
</script>
0
multisites
Asked:
multisites
  • 3
1 Solution
 
ZontarCommented:
current_form.SERVER_UPD.value = current_form.SERVER.value.replace(/^[mail|www]\.([\w|\-]+\.\w+)/i,'srv.$1');
0
 
multisitesAuthor Commented:
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:

<form>    
<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')">
</form>

Your new code:

<form>    
<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')">
</form>

Thanks for helping.
0
 
kellysgreenCommented:
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')">

0
 
multisitesAuthor Commented:
Hi:

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

Mario./
0
 
multisitesAuthor Commented:
Wow, after many attempts I got the right syntax. See:

<form>    
<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')">
</form>

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

Mario./
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now