0

In my php project i have a javascript variable say "addText" which contains the following html content

<div class="foxcontainer" style="width:100% !important;">
<h2>FREE IN HOME CONSULTATION</h2>

<ul class="fox_messages">
    <li>Invalid field: Your name</li>
    <li>Invalid field: Your email</li>
</ul>

<form enctype="multipart/form-data" class="foxform" action="/hima/bigriglawgroup/index.php/about-us#mid_131" method="post">
<!-- mod_foxcontact 2.0.19 GNU/GPLv3 -->
<div class="foxfield">
    <input class="invalidfoxtext" value="Your name" title="Your name" style="width:85% !important;display:block;float:none;margin:0 auto !important;" name="_c31f7a92d344f9a5c23d07fd438ba0b6" onfocus="if(this.value==this.title) this.value='';" onblur="if(this.value=='') this.value=this.title;" type="text"> 
    <span class="asterisk"></span>
</div>
<div class="foxfield">
    <input class="invalidfoxtext" value="Your email" title="Your email" style="width:85% !important;display:block;float:none;margin:0 auto !important;" name="_4fd8a7bb907c63baca708086b63eb7f0" onfocus="if(this.value==this.title) this.value='';" onblur="if(this.value=='') this.value=this.title;" type="text"> 
    <span class="asterisk"></span>
</div>
<div class="foxfield">
    <input class="validfoxtext" value="Phone number" title="Phone number" style="width:85% !important;display:block;float:none;margin:0 auto !important;" name="_68a05eb930e9ce854ed0c2d2d25c14a1" onfocus="if(this.value==this.title) this.value='';" onblur="if(this.value=='') this.value=this.title;" type="text">
</div>
<div class="foxfield">
    <textarea rows="" cols="" class="validfoxtext" name="_0ef408e84316ef5737db72a727579f48" title="Notes" style="width:85% !important;height:180px !important;display:block;float:none;margin:0 auto !important;" onfocus="if(this.value==this.title) this.value='';" onblur="if(this.value=='') this.value=this.title;">retret ret ret ret</textarea>
</div>
<div class="foxfield">
    <button class="foxbutton" type="submit" style="margin-right:32px;" name="mid_131">
    <span>Submit</span>
    </button>
</div>
<div class="fox-copyright" style="padding:10px 0 !important;text-indent:0 !important">
    <a target="_blank" title="Joomla contact form" href="#" style="display: none !important; display: inline !important; font-size:10px !important;">powered  by fox contact</a>
</div>

</form>

</div>

here I want to check the string "Invalid field" is present or not in that content. If it's not present I want to do some other functionality.But I don't know How to do this

Does any one know this ? Please help me ASPS.

Thanks in advance

Toretto
  • 4,721
  • 5
  • 27
  • 46
  • 1
    Read this: http://stackoverflow.com/questions/5296268/fastest-way-to-check-a-string-contain-another-substring-in-javascript – GBD Nov 30 '12 at 11:31

3 Answers3

1
if (addText.indexOf("Invalid field") != -1) { /* it's present */ }

// OR with regex

if (/Invalid field/.test(addText)) { /* it's present */ }

// OR with case-insensitve regex:

if (/Invalid field/i.test(addText)) { /* it's present */ }
nnnnnn
  • 147,572
  • 30
  • 200
  • 241
0

you can use strstr , document @ http://www.php.net/manual/en/function.strstr.php

Thanks

Oxi
  • 2,918
  • 17
  • 28
0

I really don't recommend parsing html with regex, but there's no easy way in vanilla javascript.
If you use jQuery, then this is quite a simple task with the :contains selector :

var toSearch = "Invalid field"
    elements = $(':contains('+ toSearch +')');

// if we have any elements that contain the searched keywords
if(elements.length) {
    // do smth
}
gion_13
  • 41,171
  • 10
  • 96
  • 108