Solved

Input Field Substitution - II

Posted on 2003-12-09
5
161 Views
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.

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
Comment
Question by:multisites
  • 3
5 Comments
 
LVL 11

Accepted Solution

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

Author Comment

by:multisites
Comment Utility
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
 
LVL 1

Expert Comment

by:kellysgreen
Comment Utility
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
 

Author Comment

by:multisites
Comment Utility
Hi:

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

Mario./
0
 

Author Comment

by:multisites
Comment Utility
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

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Suggested Solutions

Introduction Since I wrote the original article about Handling Date and Time in PHP and MySQL (http://www.experts-exchange.com/articles/201/Handling-Date-and-Time-in-PHP-and-MySQL.html) several years ago, it seemed like now was a good time to updat…
SASS allows you to treat your CSS code in a more OOP way. Let's have a look on how you can structure your code in order for it to be easily maintained and reused.
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 count occurrences of each item in an array.

763 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

Need Help in Real-Time?

Connect with top rated Experts

8 Experts available now in Live!

Get 1:1 Help Now