/    Sign up×
Community /Pin to ProfileBookmark

Search for specific string, return whats after it.

Find a specific string in a online text box (description), and then count and grab every letter until the period.

Hello. First time poster, long time lurker.

I am not a JS programmer, my experience comes from old Visual Basic. I started in VB 3.0 and started with the old Web 1.0/html JS. I am not up on the current languages. That said, I am asking for help with this. I will give you credit in the notes for anyone who can help me out.

I need to write a script that does the follow:

I am the webmaster of a site that sells products. Every one of our posts start out with “You’re viewing a “. Everything after that last space needs to be grabbed until the sentence ends with a period. That grabbed string then needs to be saved as a variable and the recalled into its own text box to be used a a custom label.

I assume we can use search() and some other functions to get this done.

If it doesn’t find what we are looking for i need it to return an error and then simply display nothing in the custom textbox.

Please help me out guys. I do not have too much time to get this done. Also, if you’re unwilling to help maybe you guys know a cheap custom programer I can hire. I know there are websites out there, but for the life of me i forget which ones i used in the past.

Thank you for reading and your anticipated assistance.

to post a comment
CSSHTMLJavaScript

6 Comments(s)

Copy linkTweet thisAlerts:
@JMRKERMar 06.2020 — Do you have any sample strings to parse after ..."viewing a ."?

Have you created a layout of the input and output fields you wish to display?

There is a lot of missing information as to what you are trying to accomplish so a brief example of your input and expected outputs would at least start some further discussions toward a solution.
Copy linkTweet thisAlerts:
@VITSUSAMar 06.2020 — There are so many things are missing like input and output fields, etc...please explain more about the topic.
Copy linkTweet thisAlerts:
@darklichauthorMar 06.2020 — Thank you for your replies. Sample listing below. Bold text is what i would be grabbing and storing into a variable and then putting into a label or textbox. I will enclose a copy photo as well. Not all these strings will be the same length on these different listings, so we would need count and/or grab everything from the first 'a' to the first '.'

Description

You’re viewing a **2015 Mack CXU613 Pinnacle Day Cab Tractor Automatic #043XXX4**. This truck is powered by a 395 HP 10.8L motor and a 10 speed manual transmission with 442,759 miles. The interior features power windows, power locks, power heated mirrors, air conditioning, cruise control, trailer air, air brake, inter axle lock, traction control, engine brake, suspension dump, and an AM/FM/CD radio. This truck sits on air suspension, steel rims, 275 80 24.5 tires at 65% life, and is equipped with two fuel tanks, 75 and 30 gallons. Call today!

VIN – 1M1AW02YXXXXXXXX

LENGTH – 300″

WIDTH – 96″

HEIGHT – 113″

WHEELBASE – 185″
Copy linkTweet thisAlerts:
@darklichauthorMar 06.2020 — @darklich#1615778 [upl-image-preview url=https://www.webdeveloper.com/assets/files/2020-03-06/1583505068-505046-javascipt-example.jpeg]
Copy linkTweet thisAlerts:
@JMRKERMar 06.2020 — This is designed to be modified further, but it may give you a start in your project.

<i>
</i>&lt;!DOCTYPE html&gt;&lt;html lang="en"&gt;&lt;head&gt;
&lt;title&gt; Truck Inventory &lt;/title&gt;
&lt;meta charset="UTF-8"&gt;
&lt;meta name="viewport" content="width-device-width,initial-scale=1.0, user-scalable=yes"/&gt;
&lt;!-- For: https://www.webdeveloper.com/d/388955-search-for-specific-string-return-whats-after-it/2 --&gt;
&lt;style&gt;
img { border: 1px solid red; }
.invInfo { font-size: 1.2em; font-weight: bold; background: pink; width: 35em; }
.desc {
background: #ffff00;
width: 40em;
border: 3px solid lime;
}
&lt;/style&gt;

&lt;/head&gt;&lt;body&gt;
&lt;h1&gt; Truck Ads &lt;/h1&gt;
&lt;h2&gt; Inventory &lt;/h2&gt;

&lt;div class="inventory"&gt;
&lt;img src="Mack Truck" alt="Image of Truck"&gt;
&lt;p id="invHead" class="invInfo"&gt;Info&lt;/p&gt;
&lt;h3&gt;Description&lt;/h3&gt;
&lt;p class="desc"&gt;
You’re viewing a 2015 Mack CXU613 Pinnacle Day Cab Tractor Automatic #043XXX4. This truck is powered by a 395 HP 10.8L motor and a 10
speed manual transmission with 442,759 miles. The interior features power windows, power locks, power heated mirrors, air conditioning, cruise control, trailer air, air brake, inter axle lock, traction control, engine brake, suspension dump, and an AM/FM/CD radio. This truck sits on air suspension, steel rims, 275 80 24.5 tires at 65% life, and is equipped with two fuel tanks, 75 and 30 gallons. Call today!
&lt;/p&gt;
&lt;pre&gt;
VIN – 1M1AW02YXXXXXXXX

LENGTH – 300″
WIDTH – 96″
HEIGHT – 113″
WHEELBASE – 185″
&lt;/pre&gt;
&lt;/div&gt;

&lt;script&gt;

// var inv; // collection of inventory items
// var item; // specific item of inventory

function updateInfo() {
var inv = document.querySelector('.inventory'); // alert(inv.length);
var item = inv.querySelector('.desc').textContent; // alert(item);
var desc = item.substring(item.indexOf('viewing a ')+10,item.indexOf('.')); // alert(desc);
document.getElementById('invHead').textContent = desc;
}
updateInfo();
&lt;/script&gt;

&lt;/body&gt;&lt;/html&gt;


BTW, welcome to the forums.

:)
Copy linkTweet thisAlerts:
@darklichauthorMar 06.2020 — Thank you very much for the response. I am anxious to dig into it. Thank you. =)
×

Success!

Help @darklich spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 4.23,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,

tipper: @Samric24,
tipped: article
amount: 1000 SATS,
)...