0

I'm making a form with a datepicker. The action of the form is the url of a booking web site, so I need the arrival date. But, I need to explode/split the date before submitting the form.

However, i'm using Visual Composer. So i can't add PHP in my code and I can't add event on my HTML (when I add onclick='submitForm()' for example, I save but it disappeared).

So I thought to make a function in JS to split the date but as I can't add event on my HTML, it's not working...

So I want to know how do I add event in my HTML and how to get my $_GET['beginDate'] that I want to explode to my JS code (to have

var myDate = $_GET['beginDate']; 
var tabDate = myDate.split("-"); 

)

I'm stuck here... It's for the reservit API.

Thanks for your help !

John Slegers
  • 45,213
  • 22
  • 199
  • 169
  • So you want `$_GET['beginDate']`on client side in javascript right? There is no http request yet since javascript runs on the client. Therefore you need to get the value of the element with javascript. jquery is great for this `$('#beginDate').val()` It helps if you show us what you have so far to help you further. – Mark Baijens May 30 '17 at 13:48
  • Sorry if i'm not being clear... i have to explode/slip my date so that it could go on paramaters on my url. but visual composer doesn't allowed me to add php or js code – M. Tartreau May 30 '17 at 13:50
  • even if you are using visual composer you should be able to add custom javascript in the header or footer of the page – 404answernotfound May 30 '17 at 13:54
  • Is there any visual composer element that works as a JS container, like "JS Raw" ? – 404answernotfound May 30 '17 at 13:54
  • I'm not common with visual-composer. Could be done pretty easy normally with jQuery and ajax. – Mark Baijens May 30 '17 at 13:55
  • [code]
    I've go this for my form (simplified). I'm not using data in a particular file, the date should look like fday, fmonth and fyear for the booking API. But i don't know how to split my date before the submitting. Note that onclick="submitFonctionslip" disappear after i save my page...
    – M. Tartreau May 30 '17 at 13:55
  • Yes there is a JS RAW on visual composer. But I can't add any event on my form.. – M. Tartreau May 30 '17 at 13:56
  • Try to add If it works you can pretty much add your code as events are working. – 404answernotfound May 30 '17 at 14:00
  • how do i add for example onclick from JS RAW ? (i'm pretty bad in js and jquery...) – M. Tartreau May 30 '17 at 14:02
  • if you have found the answer please update the post or accept my answer if that was the right one – 404answernotfound May 31 '17 at 06:21

1 Answers1

0

With VisualComposer add a JS RAW with this:

<script> 
jQuery(document).ready(function(){
    jQuery("button-of-your-choice").on("click", function(e){
        e.preventDefault();
        alert("button clicked!");
    });
}); 
</script> 

"button-of-your-choice" could be any html element, id or class.