Go Back   CodingForums.com > :: Client side development > JavaScript programming

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 06-17-2002, 04:41 PM   PM User | #1
BillL
New to the CF scene

 
Join Date: Jun 2002
Location: NY, NY
Posts: 9
Thanks: 0
Thanked 0 Times in 0 Posts
BillL is an unknown quantity at this point
Passing a piece of text.........

I would like to only pass a piece of data from a text box.....

If a user enters a machine name WXXX0999 (all workstation have the same naming convention) I want to only pul the XXX0 part of that name.

Any ideas....


Thanks
BillL is offline   Reply With Quote
Old 06-17-2002, 04:57 PM   PM User | #2
ACJavascript
Regular Coder

 
Join Date: Jun 2002
Location: FL, USA
Posts: 734
Thanks: 0
Thanked 0 Times in 0 Posts
ACJavascript is on a distinguished road
Question

what do you want to do with the text you pull, i don't quite understand.

You pull the XXX0 part from the textbox that has WXXX0999

then what happens to the XXX0 part.

To create a function that will probably find and remove that text(part) i need to know how to place it within the function


__________________
CYWebmaster.com - See why we dot com!!
ACJavascripts.com - Cut & Paste Javascripts!
SimplyProgram.com - Personal Blog
ACJavascript is offline   Reply With Quote
Old 06-17-2002, 05:03 PM   PM User | #3
BillL
New to the CF scene

 
Join Date: Jun 2002
Location: NY, NY
Posts: 9
Thanks: 0
Thanked 0 Times in 0 Posts
BillL is an unknown quantity at this point
It will eventually need to be submitted to SQL


Thanks
BillL is offline   Reply With Quote
Old 06-17-2002, 07:07 PM   PM User | #4
ACJavascript
Regular Coder

 
Join Date: Jun 2002
Location: FL, USA
Posts: 734
Thanks: 0
Thanked 0 Times in 0 Posts
ACJavascript is on a distinguished road
That cannot be done with javascrpit you will need to use a server-side script, i suggest useing cgi.

Yes in javascrpit you can find a piece of text and do things with it like replace it, or change it ect. but to submit it to SQL that can only be done useing server-side languages.

If i'm wrong please someone let me know.
__________________
CYWebmaster.com - See why we dot com!!
ACJavascripts.com - Cut & Paste Javascripts!
SimplyProgram.com - Personal Blog
ACJavascript is offline   Reply With Quote
Old 06-17-2002, 08:02 PM   PM User | #5
Ökii
Regular Coder

 
Join Date: Jun 2002
Location: UK
Posts: 577
Thanks: 0
Thanked 0 Times in 0 Posts
Ökii is an unknown quantity at this point
If they are all pretty much the same style of machine name, why
ask the user to enter the lot?

Please complete your machine name<br>
W <input type="text" name="machnam" width="40" maxlength="4"></input> 999
__________________
Ökii - formerly pootergeist
teckis - take your time and it'll save you time.
Ökii is offline   Reply With Quote
Old 06-17-2002, 08:22 PM   PM User | #6
amy2go
New Coder

 
Join Date: Jun 2002
Location: Dallas
Posts: 23
Thanks: 0
Thanked 0 Times in 0 Posts
amy2go is an unknown quantity at this point
function fnTest(){
var longMachine = new Array;
longMachine[0] = fname.mname.value;
var shortMachine = "";
for(i=1; i<5; i++){
shortMachine += longMachine[0].charAt(i);
}
window.alert(shortMachine);
}

<form name=fname>
<input name=mname type=text value="wxxx0999">
<input type=button onclick="fnTest()" value=Test>
</form>

Maybe this is going about it the long way, but I use the array.Split method with this to validate input boxes. Since you don't need the .Split, you could just use this. I tested it for you and the xxx0 will end up in variable shortMachine. (I didn't check for empty strings, so you might want to add that.) Hope this helps.

-Amy
amy2go is offline   Reply With Quote
Old 06-17-2002, 08:33 PM   PM User | #7
jkd
Senior Coder

 
jkd's Avatar
 
Join Date: May 2002
Location: metro DC
Posts: 3,163
Thanks: 1
Thanked 18 Times in 18 Posts
jkd will become famous soon enough
function getShort(str) {
return str.match(/W(.{4})999/i)[1];
}


getShort('WXXX0999') == 'XXX0'; //true
__________________
jasonkarldavis.com
jkd is offline   Reply With Quote
Old 06-18-2002, 01:05 AM   PM User | #8
whammy
Senior Coder

 
Join Date: Jun 2002
Location: 41° 8' 52" N -95° 53' 31" W
Posts: 3,660
Thanks: 0
Thanked 0 Times in 0 Posts
whammy is an unknown quantity at this point
I would go with the regular expression jkd posted.

Regular Expression = elegant (and sexy code).
__________________
Former ASP Forum Moderator - I'm back!

If you can teach yourself how to learn, you can learn anything. ;)
whammy is offline   Reply With Quote
Old 06-18-2002, 10:33 AM   PM User | #9
Beck
New Coder

 
Join Date: Jun 2002
Posts: 72
Thanks: 0
Thanked 0 Times in 0 Posts
Beck is an unknown quantity at this point
WXXX0999 (all workstation have the same naming convention)
pulling the XXX0 part...

You're getting it from a textbox, so go ahead and stick it in a variable, say myString. For retrieving the XXX0 part, use :

var XXX0 = myString.substring(1,5);

This will return the value of XXX0 from WXXX0999. This way you can avoid those intimidating regular expressions!
__________________
If at first you don't succeed, spend more time online researching javascript!
Beck
Beck is offline   Reply With Quote
Old 06-18-2002, 01:28 PM   PM User | #10
amy2go
New Coder

 
Join Date: Jun 2002
Location: Dallas
Posts: 23
Thanks: 0
Thanked 0 Times in 0 Posts
amy2go is an unknown quantity at this point
Okay, so maybe I need to spend a little more time than a couple of months learning Javascript, Perl, and all this web programming before trying to help out. Hey it may be long but it worked!

-Amy
amy2go is offline   Reply With Quote
Old 06-18-2002, 01:31 PM   PM User | #11
BillL
New to the CF scene

 
Join Date: Jun 2002
Location: NY, NY
Posts: 9
Thanks: 0
Thanked 0 Times in 0 Posts
BillL is an unknown quantity at this point
Thanks.... I can use all the help I can get.... It's good for me to see different ways to do things....
BillL is offline   Reply With Quote
Old 06-18-2002, 11:47 PM   PM User | #12
whammy
Senior Coder

 
Join Date: Jun 2002
Location: 41° 8' 52" N -95° 53' 31" W
Posts: 3,660
Thanks: 0
Thanked 0 Times in 0 Posts
whammy is an unknown quantity at this point
There's nothing wrong with your solution either, Amy!
__________________
Former ASP Forum Moderator - I'm back!

If you can teach yourself how to learn, you can learn anything. ;)
whammy is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 03:22 AM.


Advertisement
Log in to turn off these ads.