Help with code for switching the text? Anyone?

Support for iMacros. The iMacros software is the unique solution for automating every activity inside a web browser, for data extraction and web testing.
Forum rules
iMacros EOL - Attention!

The renewal maintenance has officially ended for Progress iMacros effective November 20, 2023 and all versions of iMacros are now considered EOL (End-of-Life). The iMacros products will no longer be supported by Progress (aside from customer license issues), and these forums will also no longer be moderated from the Progress side.

Thank you again for your business and support.

Sincerely,
The Progress Team

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
manotop
Posts: 12
Joined: Wed Aug 24, 2016 1:01 pm

Help with code for switching the text? Anyone?

Post by manotop » Wed Aug 24, 2016 1:06 pm

For example
if text is = abc then switch it to xyz.

or

if text is = xyz the switch to abc.


Please help me with the code!
chivracq
Posts: 10301
Joined: Sat Apr 13, 2013 1:07 pm
Location: Amsterdam (NL)

Re: Help with code for switching the text? Anyone?

Post by chivracq » Thu Aug 25, 2016 2:27 pm

manotop wrote:For example
if text is = abc then switch it to xyz.

or

if text is = xyz the switch to abc.


Please help me with the code!
No need to open Duplicates Threads when you open a Thread... (I've deleted the Duplicate.)

CIM...! :mrgreen: (Always mention your FCI when you open a Thread, read my Sig, many Commands are not implemented for all Browsers/Versions...)

For your Qt, yep, use 'EVAL()' + 'replace()'. (Many Examples on the Forum...)
- (F)CI(M) = (Full) Config Info (Missing): iMacros + Browser + OS (+ all 3 Versions + 'Free'/'PE'/'Trial').
- FCI not mentioned: I don't even read the Qt...! (or only to catch Spam!)
- Script & URL help a lot for more "educated" Help...
manotop
Posts: 12
Joined: Wed Aug 24, 2016 1:01 pm

Re: Help with code for switching the text? Anyone?

Post by manotop » Fri Aug 26, 2016 5:22 am

Sorry, i accidently made duplicate thread. BTW what does CIM and FCI stands for? I googled but found very odd abbreviations :oops:
Thanks for the hint!
chivracq wrote:
manotop wrote:For example
if text is = abc then switch it to xyz.

or

if text is = xyz the switch to abc.


Please help me with the code!
No need to open Duplicates Threads when you open a Thread... (I've deleted the Duplicate.)

CIM...! :mrgreen: (Always mention your FCI when you open a Thread, read my Sig, many Commands are not implemented for all Browsers/Versions...)

For your Qt, yep, use 'EVAL()' + 'replace()'. (Many Examples on the Forum...)
chivracq
Posts: 10301
Joined: Sat Apr 13, 2013 1:07 pm
Location: Amsterdam (NL)

Re: Help with code for switching the text? Anyone?

Post by chivracq » Fri Aug 26, 2016 5:51 am

manotop wrote:Sorry, i accidently made duplicate thread. BTW what does CIM and FCI stands for? I googled but found very odd abbreviations :oops:
Thanks for the hint!
Hum, I googled as well "CIM + FCI + iMacros" and the first Hit is on the iMacros Forum and the second one on Stackoverflow, both with full explanation of what they mean... :roll:
Searching the Forum for any Acronym would be even more "powerful", and reading 1 cm below this Post, => my Sig...!, even easier... :idea:
=> Search found 791 matches: CIM
=> Search found 662 matches: FCI
- (F)CI(M) = (Full) Config Info (Missing): iMacros + Browser + OS (+ all 3 Versions + 'Free'/'PE'/'Trial').
- FCI not mentioned: I don't even read the Qt...! (or only to catch Spam!)
- Script & URL help a lot for more "educated" Help...
manotop
Posts: 12
Joined: Wed Aug 24, 2016 1:01 pm

Re: Help with code for switching the text? Anyone?

Post by manotop » Fri Aug 26, 2016 8:17 am

I feel like a total noob right now :cry:
chivracq wrote:
manotop wrote:Sorry, i accidently made duplicate thread. BTW what does CIM and FCI stands for? I googled but found very odd abbreviations :oops:
Thanks for the hint!
Hum, I googled as well "CIM + FCI + iMacros" and the first Hit is on the iMacros Forum and the second one on Stackoverflow, both with full explanation of what they mean... :roll:
Searching the Forum for any Acronym would be even more "powerful", and reading 1 cm below this Post, => my Sig...!, even easier... :idea:
=> Search found 791 matches: CIM
=> Search found 662 matches: FCI
manotop
Posts: 12
Joined: Wed Aug 24, 2016 1:01 pm

Script for replacing the text with condition?

Post by manotop » Tue Aug 30, 2016 3:25 pm

I want to build a code for the form:

if text is = XYZ then switch it to ABC.

AND

if text is = XYZ then switch to ABC.



Please pay attention to the Script number 2:

Script number 1: Extract text line (this will get the text):

Code: Select all

TAG POS=1 TYPE=INPUT:TEXT FORM=ID:newOffer ATTR=ID:add-title EXTRACT=TXT
Script number 2: I found the below script on the forum but it only replaces the whole string and first of all it has no second condition and I am not sure how to implement it with this code below:

Code: Select all

SET !VAR2 EVAL("var extr2=\"{{!EXTRACT}}\"; extr2.replace(\"ABC\",\"XYZ\"); ")
Script number 3: Add the texts:

Code: Select all

TAG POS=1 TYPE=INPUT:TEXT FORM=ID:newOffer ATTR=ID:add-title CONTENT={{!VAR2}}
P.S. I did some research and find out that I need to set some type of if else or true/false condition but I couldn't make it to work as I am not good at JavaScript.


I am using: Mac OS 10.11, FireFox iMacro 8.9.7, FireFox v48.02
iimfun
Posts: 239
Joined: Tue Jul 19, 2016 1:06 pm

Re: Script for replacing the text with condition?

Post by iimfun » Thu Sep 01, 2016 7:18 am

Maybe this code?

Code: Select all

SET !VAR2 EVAL("('{{!EXTRACT}}' == 'ABC') ? 'XYZ' : 'ABC';")
manotop
Posts: 12
Joined: Wed Aug 24, 2016 1:01 pm

Re: Script for replacing the text with condition?

Post by manotop » Thu Sep 01, 2016 7:55 am

First of all thanks for taking the time to reply.

For some reasons the code isnt working when I run it. Its not even replacing ABC to XYZ.
How about if the text is XYZ then switch it to ABC? Also please keep in mind that I want this to be run in one single code. Because if there are two separate codes it will replace ABC back to ABC (ABC > XYZ > XYZ > ABC) so I want to make sure that it doesnt run it twice. I hope you can understand. If you want more explanation please let me know.
Thanks again :)
iimfun wrote:Maybe this code?

Code: Select all

SET !VAR2 EVAL("('{{!EXTRACT}}' == 'ABC') ? 'XYZ' : 'ABC';")
iimfun
Posts: 239
Joined: Tue Jul 19, 2016 1:06 pm

Re: Script for replacing the text with condition?

Post by iimfun » Thu Sep 01, 2016 12:33 pm

Did you test in the following way?

Code: Select all

SET !EXTRACT "ABC"
SET !VAR2 EVAL("('{{!EXTRACT}}' == 'ABC') ? 'XYZ' : 'ABC';")
PROMPT {{!VAR2}}
chivracq
Posts: 10301
Joined: Sat Apr 13, 2013 1:07 pm
Location: Amsterdam (NL)

Re: Script for replacing the text with condition?

Post by chivracq » Thu Sep 01, 2016 4:14 pm

manotop wrote:I want to build a code for the form:

if text is = XYZ then switch it to ABC.

AND

if text is = XYZ then switch to ABC.



Please pay attention to the Script number 2:

Script number 1: Extract text line (this will get the text):

Code: Select all

TAG POS=1 TYPE=INPUT:TEXT FORM=ID:newOffer ATTR=ID:add-title EXTRACT=TXT
Script number 2: I found the below script on the forum but it only replaces the whole string and first of all it has no second condition and I am not sure how to implement it with this code below:

Code: Select all

SET !VAR2 EVAL("var extr2=\"{{!EXTRACT}}\"; extr2.replace(\"ABC\",\"XYZ\"); ")
Script number 3: Add the texts:

Code: Select all

TAG POS=1 TYPE=INPUT:TEXT FORM=ID:newOffer ATTR=ID:add-title CONTENT={{!VAR2}}
P.S. I did some research and find out that I need to set some type of if else or true/false condition but I couldn't make it to work as I am not good at JavaScript.


I am using: Mac OS 10.11, FireFox iMacro 8.9.7, FireFox v48.02
iimfun wrote:Maybe this code?

Code: Select all

SET !VAR2 EVAL("('{{!EXTRACT}}' == 'ABC') ? 'XYZ' : 'ABC';")
manotop wrote:First of all thanks for taking the time to reply.

For some reasons the code isnt working when I run it. Its not even replacing ABC to XYZ.
How about if the text is XYZ then switch it to ABC? Also please keep in mind that I want this to be run in one single code. Because if there are two separate codes it will replace ABC back to ABC (ABC > XYZ > XYZ > ABC) so I want to make sure that it doesnt run it twice. I hope you can understand. If you want more explanation please let me know.
Thanks again :)
iimfun wrote:Maybe this code?

Code: Select all

SET !VAR2 EVAL("('{{!EXTRACT}}' == 'ABC') ? 'XYZ' : 'ABC';")
iimfun wrote:Did you test in the following way?

Code: Select all

SET !EXTRACT "ABC"
SET !VAR2 EVAL("('{{!EXTRACT}}' == 'ABC') ? 'XYZ' : 'ABC';")
PROMPT {{!VAR2}}
Hum..., @OP, good to see that you finally understood my Request to mention your FCI but there was no need to open a Duplicate Thread, you should have followed up and posted this Info (and your "more Info") in your Original Thread, so this current one will be merged with the Original one... and I won't try to help you anymore in the future... :roll: Good luck with @iimfun and other Advanced Users... (Sorry but I only help Users using the Forum a bit correctly... :roll: )
- (F)CI(M) = (Full) Config Info (Missing): iMacros + Browser + OS (+ all 3 Versions + 'Free'/'PE'/'Trial').
- FCI not mentioned: I don't even read the Qt...! (or only to catch Spam!)
- Script & URL help a lot for more "educated" Help...
manotop
Posts: 12
Joined: Wed Aug 24, 2016 1:01 pm

Re: Script for replacing the text with condition?

Post by manotop » Fri Sep 02, 2016 6:56 am

So sorry about that I will pay attention to the forum rules next time.
chivracq wrote:
manotop wrote:I want to build a code for the form:

if text is = XYZ then switch it to ABC.

AND

if text is = XYZ then switch to ABC.



Please pay attention to the Script number 2:

Script number 1: Extract text line (this will get the text):

Code: Select all

TAG POS=1 TYPE=INPUT:TEXT FORM=ID:newOffer ATTR=ID:add-title EXTRACT=TXT
Script number 2: I found the below script on the forum but it only replaces the whole string and first of all it has no second condition and I am not sure how to implement it with this code below:

Code: Select all

SET !VAR2 EVAL("var extr2=\"{{!EXTRACT}}\"; extr2.replace(\"ABC\",\"XYZ\"); ")
Script number 3: Add the texts:

Code: Select all

TAG POS=1 TYPE=INPUT:TEXT FORM=ID:newOffer ATTR=ID:add-title CONTENT={{!VAR2}}
P.S. I did some research and find out that I need to set some type of if else or true/false condition but I couldn't make it to work as I am not good at JavaScript.


I am using: Mac OS 10.11, FireFox iMacro 8.9.7, FireFox v48.02
iimfun wrote:Maybe this code?

Code: Select all

SET !VAR2 EVAL("('{{!EXTRACT}}' == 'ABC') ? 'XYZ' : 'ABC';")
manotop wrote:First of all thanks for taking the time to reply.

For some reasons the code isnt working when I run it. Its not even replacing ABC to XYZ.
How about if the text is XYZ then switch it to ABC? Also please keep in mind that I want this to be run in one single code. Because if there are two separate codes it will replace ABC back to ABC (ABC > XYZ > XYZ > ABC) so I want to make sure that it doesnt run it twice. I hope you can understand. If you want more explanation please let me know.
Thanks again :)
iimfun wrote:Maybe this code?

Code: Select all

SET !VAR2 EVAL("('{{!EXTRACT}}' == 'ABC') ? 'XYZ' : 'ABC';")
iimfun wrote:Did you test in the following way?

Code: Select all

SET !EXTRACT "ABC"
SET !VAR2 EVAL("('{{!EXTRACT}}' == 'ABC') ? 'XYZ' : 'ABC';")
PROMPT {{!VAR2}}
Hum..., @OP, good to see that you finally understood my Request to mention your FCI but there was no need to open a Duplicate Thread, you should have followed up and posted this Info (and your "more Info") in your Original Thread, so this current one will be merged with the Original one... and I won't try to help you anymore in the future... :roll: Good luck with @iimfun and other Advanced Users... (Sorry but I only help Users using the Forum a bit correctly... :roll: )
manotop
Posts: 12
Joined: Wed Aug 24, 2016 1:01 pm

Re: Script for replacing the text with condition?

Post by manotop » Fri Sep 02, 2016 7:04 am

@iimfun u are a genius! It actually works!

BTW I am not sure if I am allowed to ask it out on the same post or not but I will ask you anyway as I have made a post on the forum a while back and nobody was able to answer it. Right now the last piece of this whole thing is I want the script to check which day is it and run/stop accordingly.

For example:
Check if the today is Monday or Wednesday or Friday if true Continue the script. Otherwise stop the script.


Thanks
iimfun wrote:Did you test in the following way?

Code: Select all

SET !EXTRACT "ABC"
SET !VAR2 EVAL("('{{!EXTRACT}}' == 'ABC') ? 'XYZ' : 'ABC';")
PROMPT {{!VAR2}}
iimfun
Posts: 239
Joined: Tue Jul 19, 2016 1:06 pm

Re: Script for replacing the text with condition?

Post by iimfun » Fri Sep 02, 2016 4:55 pm

manotop wrote:For example:
Check if the today is Monday or Wednesday or Friday if true Continue the script. Otherwise stop the script.
Play carefully this line

Code: Select all

SET checkDay EVAL("var d = (new Date()).toString(); (d.match(/^(Mon|Wed|Fri)/)) ? 'CONTINUE' : MacroError(d + ' => STOP !');")
manotop
Posts: 12
Joined: Wed Aug 24, 2016 1:01 pm

Re: Script for replacing the text with condition?

Post by manotop » Sat Sep 03, 2016 8:58 am

F*cking nice. I am also learning JS too. How much time do i have to spend to get to your level? I am learning from Treehouse and Codeacademy sites is it ok to learn from them or do you have a better recommendation?
iimfun wrote:
manotop wrote:For example:
Check if the today is Monday or Wednesday or Friday if true Continue the script. Otherwise stop the script.
Play carefully this line

Code: Select all

SET checkDay EVAL("var d = (new Date()).toString(); (d.match(/^(Mon|Wed|Fri)/)) ? 'CONTINUE' : MacroError(d + ' => STOP !');")
iimfun
Posts: 239
Joined: Tue Jul 19, 2016 1:06 pm

Re: Script for replacing the text with condition?

Post by iimfun » Mon Sep 05, 2016 7:50 am

Well, learn JS by any tutorials that you like and just try to solve hard tasks. The progress depends mostly on your own efforts and sometimes on good advices. Good luck!
Post Reply