0

We have just got a new CRM system that manages our online forms and I can manipulate it using JQuery to complete extra functions.

This is something we are doing on our current website where I am able to use pathnames to complete sections of the form.

For example... <URL>/John%20Smith/50 would preload the form with John Smith under name and £50 under donation.

Here is my current code for the new system:

<script>
window.addEventListener( 'load', function() {
    var pageName = $(location).attr('pathname').split('/');
    var arr = $.makeArray(pageName);    
    $('input[name=field[91]]').eq(0).val(arr);
    $('input[name=field[9]]').eq(1).val(arr);
});
</script>
2
  • You're sharing some discovery or you have some actual problem to solve? Also... why is <script> inside <style> ? Commented May 21, 2020 at 16:58
  • See this fiddle: jsfiddle.net/9s3eugc8 Commented May 21, 2020 at 17:26

1 Answer 1

1

I am posting it as an answer here:

// suppose window.location = "https://<your url>/John%20Smith/50"
var url = "https://<your url>/John%20Smith/50";

$(document).ready(function(){

    // $(location).attr('pathname').split('/')
    // replace this with the above code
    var pageName = url.split('/').splice(3);
    var arr = $.makeArray(pageName);    

    // if name is unique, you don't need .eq
    // you may not need decodeURIComponent if url is form window.location
    $('input[name="field[91]"]').val(decodeURIComponent(arr[0]));
    $('input[name="field[9]"]').val('£' + decodeURIComponent(arr[1]));

});

See fiddle: https://jsfiddle.net/9s3eugc8/

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.