0

If I add the hidden input field to a form:

<input name="cf_person_partner" type="hidden" value="PartnerName" />

With the form being hosted on a landing page with the URL:

https://wb.workbooks.com/process/=QzM/Webinar_Portal?eventid=1048&partner=lucid

How can I pull the partner value (in this instance lucid) from the URL into the value on the hidden input field so it becomes:

 <input name="cf_person_partner" type="hidden" value="lucid" />

Note: The site is hosted using Bootstrap and no Javascript is currently running (so I'll need to add this in).

4 Answers 4

2

you can pull this value from URL (URL obviously being window.location.href)

var url = "https://wb.workbooks.com/process/=QzM/Webinar_Portal?eventid=1048&partner=lucid";

var partnerName = url.split("partner=")[1];

document.querySelector("[name='cf_person_partner']").value = partnerName;

DEMO

    var url = "https://wb.workbooks.com/process/=QzM/Webinar_Portal?eventid=1048&partner=lucid";
    
    var partnerName = url.split("partner=")[1];

    document.querySelector("[name='cf_person_partner']").value = partnerName;
<input name="cf_person_partner" type="hidden" value="PartnerName" />

if the partner parameter is not necessarily the coming last on URL, then add this line

var partnerName = url.split("partner=")[1];
partnerName = partnerName.split( "&" )[0];
Sign up to request clarification or add additional context in comments.

5 Comments

Thanks so I'd need to add: <script> var url = "https://wb.workbooks.com/process/=QzM/Webinar_Portal?eventid=1048&partner=lucid"; var partnerName = url.split("partner=")[1]; partnerName = partnerName.split( "&" )[0]; document.querySelector("[name='cf_person_partner']").value = partnerName; </script> Plus add Javascript to the body such as: <script src="http://code.jquery.com/jquery-latest.js"></script> and no changes would be needed on the actual HTML input line?
@SamJefferies html input markup doesn't need to change. But your URL will be the value of location.href.
Thanks @gurvinder372 apologies, I'm very fresh to Javascript. I can't see the location.href in the script you provided, is this something I need to add in?
@SamJefferies Nope, it is not in my code, but you may need it. Simply replace var URL = "your URL" with var URL = location.href;
Gotcha I see! Thanks.
0

Get the value from url first

var partnerName = url.split("partner=")[1];

Assign it to the hidden field, make sure you add up an it access it, you can access with name too.

 <input name="cf_person_partner" id="hiddenValue" type="hidden" value="PartnerName" />

and update the value using jquery as :

 $('#hiddenValue').val("lucid");

you can call have javascript events to trigger this change. May be a function which will have the line that I mentioned above.

Comments

0

First you need to get the value from url, You can do this using location object:

Example:

var partnerValue = location.search.split("partner=");

then you may set the name to the field :

$("[name='cf_person_partner']").value(partnerValue)

Comments

0

you can use below Javascript code:

Common function for getting URL parameters:

function getUrlVars() {
            var vars = [], hash;
            var hashes = window.location.href.slice(window.location.href.indexOf('?') + 1).split('&');
            for (var i = 0; i < hashes.length; i++) {
                hash = hashes[i].split('=');
                vars.push(hash[0]);
                vars[hash[0]] = hash[1];
            }
            return vars;

and assign to hidden field like below:

document.querySelector("[name='cf_person_partner']").value = getUrlVars()["partner"];

hope it will help you, Thanks

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.