Ecommerce Shopify WordPress Discussion

handler this not working – jquery at WP backend

I would like that when Update/Publish button is pressed at Wordpress backend to update/publish a wordpress post: a) Wordpress still updates/publishes the rest of the contensts of that post b) jQuery gives a warning message if a URL entered is invalid in a form field at Wordpress backend c) then clear off or remove that invalid URL above Here are my codes: HTML: <input type="text" id="url" name="url"> jQuery: var myurl = document.getElementById('url').value; var urlRegex = /(^$)|^(http:\/\/www.|https:\/\/www.|ftp:\/\/www.|www.){1}([0-9A-Za-z]+\.)/; if (!urlRegex.test(myurl)) { alert('Its invalid URL or website. Make sure to include www'); $this.val(null); // $(this).val(null); // not working either } I have tried to use $this.val(null); or $(this).val(null); to remove that invalid URL after the post was updated/published, but URL is updated/published by Wordpress too. Please advise how to achieve the above. Many thanks
FIXED: use jQuery('#url').val(''); instead of $this.val(null); which works only inside a jQuery function. In my case that $this.val(null); does not work. This may be helpful to anyone who need similar solutions. HTML: <input type="text" id="url" name="url"> jQuery: var myurl = document.getElementById('url').value; var urlRegex = /(^$)|^(http:\/\/www.|https:\/\/www.|ftp:\/\/www.|www.){1}([0-9A-Za-z]+\.)/; if (!urlRegex.test(myurl)) { alert('Its invalid URL or website. Make sure to include www'); jQuery('#url').val(''); } Many thanks

December 30, 2023

TurboCommerce make the better internet purchasing globaly

Turbo Multi-language Translator

Make the better internet purchasing globaly

Turbosify SEO Speed Booster

5.0 (7) Free plan available
Get better conversions by improving store loading speed Installed

Turbo Multi-language Chat - AI Customer service in one hand

TurboCommerce make the better internet purchasing globaly
Our products

The help you need, when you need it

App by Turbo Engine

3 apps • 5.0 average rating

Turbosify Speed Booster

5.0 (7)
Get better conversions by optimizing shopify store Google page speed Installed

Turbosify Translator for Wordpress Woocommerce

5.0 (74) Free Wordpress Woocommerce Plugin
Translate your wordpress website to multiple language within 1 click, no configuration needed, no No technical required

Grow your business here

Whether you want to sell products down the street or around the world, we have all the tools you need.