That would scroll the page down to the element with the ID of “formanchor” (you can use a div with that ID or another element in the page with that ID) and then the myvar=rb1 would pre-select the radio button choice with the value “rb1”. You have to set up that radio button field to allow dynamic population (that is a checkbox on the field under the Advanced tab) and you have to have a matching radio button label or value of rb1.
I created a demo for you here:
[SITE REMOVED]
Try the buttons and see how the radio button are pre-selected. This is not strictly scrolling down the page (it’s a page reload) but if this works then you are all set. If this does not work, you can attach jQuery to the button to scroll to the form and pre-select one of the radio button options. That will require more work
You’re a genius. This is what I wanted. I know it’s a lot to ask but would the jQuery version be a lot more complicated? It would be a nicer experience if the page didn’t reload.
Hello. I’m glad that is close to what you want. For someone with a little bit of time and jQuery skills I don’t think it would be too difficult. However, I was not able to come up with that in the amount of time I had for this one.
It’s not the prettiest code nor is it the most correct code in the world, but I thought I’d share my jQuery solution in case anyone is interested. It’s not very dynamic, i.e. if someone needs 4 choices instead of 3 they’d need to add more code and adapt to their liking.
function ChangeUrl(page, url) {
if (typeof (history.pushState) != "undefined") {
var obj = { Page: page, Url: url };
history.pushState(obj, obj.Page, obj.Url);
}
}
jQuery(function($) {
// Give the first button this #id from the WordPress Admin.
// Repeat this function for how many buttons you have.
$("#careerChoice1").click(function () {
// This prevents the browser refreshing on click.
event.preventDefault();
// Change the url to /careers/?careerchoice=1, 2, 3, etc.
// so that if the user shares this url the form will be populated
// with the right choice.
ChangeUrl('Page1', '?careerchoice=1');
// Select the right radio button
$('#choice_2_14_0').trigger('click');
// Scroll the page to the form #applynow
$("html, body").animate({
scrollTop: $('#applynow').offset().top
}, 400);
});
});
The cool part is that if the visitor’s browser can’t run JavaScript the buttons can simply have the form ID in their href and it will gracefully degrade to a simple jump to the form.
Hope this helps anyone, at least get an idea.
If anyone has suggestions on how to make this code better please consider replying.