Copy first word from field and paste to another

Discussions and Tech Support related to the iMacros Firefox Add-on, including the built-in Javascript scripting interface for playing .js files.
Forum rules
Before asking a question or reporting an issue:
1. Please review the list of FAQ's.
2. Use the search box (at the top of each forum page) to see if a similar problem or question has already been addressed.
3. Try searching the iMacros Wiki - it contains the complete iMacros reference as well as plenty of samples and tutorials.
4. We can respond much faster to your posts if you include the following information:CLICK HERE FOR IMPORTANT INFORMATION TO INCLUDE IN YOUR POST
Post Reply
LaimisV
Posts: 22
Joined: Thu Jan 17, 2013 12:05 pm

Copy first word from field and paste to another

Post by LaimisV » Thu Jan 17, 2013 12:18 pm

Hi,
I need to copy first word (red) from the first field and extract to the second field. How can I resolve this task ?
Note: the strings can be different (for example "A B C", "white grey black", ... and I need 'A", "white", ...)

Thanks !

VERSION BUILD=7601105 RECORDER=FX
TAB T=1
URL GOTO=http://www.websitedatabases.com/php_for ... ple-2.html
TAG POS=1 TYPE=INPUT:TEXT FORM=ACTION:index.php ATTR=NAME:entry1 CONTENT=red<SP>green<SP>blue
TAG POS=1 TYPE=INPUT:TEXT FORM=ACTION:index.php ATTR=NAME:entry1 EXTRACT=TXT
SET !VAR1 {{!EXTRACT}}
SET !EXTRACT NULL

TAG POS=1 TYPE=INPUT:TEXT FORM=ACTION:index.php ATTR=NAME:entry2 CONTENT={{!VAR1}}


In this example I just copy and paste three words. I need one word.
User avatar
bobis
Posts: 364
Joined: Sat Sep 11, 2010 3:34 pm
Contact:

Re: Copy first word from field and paste to another

Post by bobis » Thu Jan 17, 2013 4:11 pm

to extract first word you can use eval :

Code: Select all

set !var3 eval("var s=\"{{!extract}}\"; s=s.split(\" \");s[0];")
Get Best iMacros scripts at http://imacrosbot.com/
LaimisV
Posts: 22
Joined: Thu Jan 17, 2013 12:05 pm

Re: Copy first word from field and paste to another

Post by LaimisV » Fri Jan 18, 2013 7:55 am

Great, it works. It's very useful in my daily tasks. Now I have some work to find out how extract word from middle or end.
LaimisV
Posts: 22
Joined: Thu Jan 17, 2013 12:05 pm

Re: Copy first word from field and paste to another

Post by LaimisV » Fri Jan 18, 2013 8:09 am

LaimisV wrote:Great, it works. It's very useful in my daily tasks. Now I have some work to find out how extract word from middle or end.
Simple answer :
set !var1 eval("var s=\"{{!extract}}\"; s=s.split(\" \");s[1];")
set !var1 eval("var s=\"{{!extract}}\"; s=s.split(\" \");s[2];")
User avatar
bobis
Posts: 364
Joined: Sat Sep 11, 2010 3:34 pm
Contact:

Re: Copy first word from field and paste to another

Post by bobis » Fri Jan 18, 2013 8:54 am

Exactly!
LaimisV wrote:
LaimisV wrote:Great, it works. It's very useful in my daily tasks. Now I have some work to find out how extract word from middle or end.
Simple answer :
set !var1 eval("var s=\"{{!extract}}\"; s=s.split(\" \");s[1];")
set !var1 eval("var s=\"{{!extract}}\"; s=s.split(\" \");s[2];")
Get Best iMacros scripts at http://imacrosbot.com/
turqoisehat
Posts: 2
Joined: Wed May 18, 2016 9:36 pm

Re: Copy first word from field and paste to another

Post by turqoisehat » Sat Sep 22, 2018 7:42 pm

Hey

This is great! I am unfamiliar with javascript so this is very helpful. I have a question that you may help me with. I have the exact same problem, except I am parsing an address line:
City, State Zipcode
Most of the time this 0 1 2 method works, but sometimes the City is more than one word. I would easily be able to program this in a more familiar language but not sure about javascript? Can I do if/then statements in the script?

Can I embed javascript functions in these little snippets of iMacro embedded javascript such as this one?
function WordCount(str) {
return str.split(" ").length;
}

Thanks
chivracq
Posts: 8525
Joined: Sat Apr 13, 2013 1:07 pm
Location: Amsterdam (NL)

Re: Copy first word from field and paste to another

Post by chivracq » Sat Sep 22, 2018 8:46 pm

turqoisehat wrote:Hey

This is great! I am unfamiliar with javascript so this is very helpful. I have a question that you may help me with. I have the exact same problem, except I am parsing an address line:
City, State Zipcode
Most of the time this 0 1 2 method works, but sometimes the City is more than one word. I would easily be able to program this in a more familiar language but not sure about javascript? Can I do if/then statements in the script?

Can I embed javascript functions in these little snippets of iMacro embedded javascript such as this one?

Code: Select all

function WordCount(str) { 
  return str.split(" ").length;
}
Thanks
Hum..., a bit surprising to see that you didn't find the time to read the Forum Rules in the 2.5 years since you joined the Forum, oops...!? :shock:
=> Mention your FCI for me to have a look, (read my Sig...), unless you prefer to put your "Hope" into that one of the original "Actors" in this Thread (from more than 5 years ago (from even before I joined the Forum)) will react and try to help you, which would surprise me... :idea:
+ If using v10.0.x for CR/FF, mention as well 'Free'/'PE'...

And it would also help/speed up Answer if you could post your Script + URL... :idea:
(No Script + No URL, I will only give you some "generic" Answer... :roll: )
- (F)CIM = (Full) Config Info Missing: iMacros + Browser + OS with all 3 Versions...
- I usually don't even read the Question if that (required) Info is not mentioned...
- Script & URL usually help a lot for a more "educated" Help...
turqoisehat
Posts: 2
Joined: Wed May 18, 2016 9:36 pm

Re: Copy first word from field and paste to another

Post by turqoisehat » Sat Sep 22, 2018 11:16 pm

Solved it. iMacros does support javascript if then statements.
chivracq
Posts: 8525
Joined: Sat Apr 13, 2013 1:07 pm
Location: Amsterdam (NL)

Re: Copy first word from field and paste to another

Post by chivracq » Sat Sep 22, 2018 11:23 pm

turqoisehat wrote:Solved it. iMacros does support javascript if then statements.
Hum, OK, Thanks for the Update..., but FCI not mentioned like I asked you, and Script/Solution not really shared ("iMacros does support javascript if then statements.", is not really a Solution, "anybody" finding iMacros while looking for a Web-Automation Solution already knows that even before they start downloading/installing iMacros... Hum, and that's not exactly/completely true..., but, OK, never mind...), glad you found your Solution/Answer... :|

Even if I'm "afraid" you probably went for a "cumbersome" Solution, no 'if/else' is needed to implement the Functionality that you want(ed)...
But OK, we'll never know as you didn't post your original Script nor the final one... :roll:
- (F)CIM = (Full) Config Info Missing: iMacros + Browser + OS with all 3 Versions...
- I usually don't even read the Question if that (required) Info is not mentioned...
- Script & URL usually help a lot for a more "educated" Help...
Post Reply