Currently working on a Dealer locator customization in Wordpress, and I have a specific requirement to adjust certain fields. One of the tasks is to conditionally hide a field based on another field's input.
The situation:
If the user enters data in the Address field but leaves the Address2 field empty, the Address element should be displayed. I managed to achieve this functionality successfully, but now I am facing a challenge with the next step. When the user fills in the Address2 field, it should display address2 and hide the Address field.
The code snippet I am presently using:
function custom_listing_template() {
global $wpsl, $wpsl_settings;
$listing_template = '<li class="my_change_list" data-store-id="<%= id %>">' . "\r\n";
$listing_template .= "\t\t" . '<div class="locator_wrap_left">' . "\r\n";
$listing_template .= "\t\t" . '<div class="locator_title">' . "\r\n";
$listing_template .= "\t\t\t\t" . wpsl_store_header_template( 'listing' ) . "\r\n";
$listing_template .= "\t\t" . '</div>' . "\r\n";
$listing_template .= "\t\t" . '<div class="locator_left">' . "\r\n";
$listing_template .= "\t\t\t" . '<p><%= thumb %>' . "\r\n";
$listing_template .= "\t\t\t\t" . '<span class="wpsl-street street1"><%= address %></span>' . "\r\n";
$listing_template .= "\t\t\t\t" . '<% if (address2) { %>' . "\r\n";
$listing_template .= "\t\t\t\t" . ' <span class="wpsl-street street2"><%= address2 %></span>' . "\r\n";
$listing_template .= "\t\t\t\t" . '<% } %>' . "\r\n";
$listing_template .= "\t\t\t\t" . '<span>' . wpsl_address_format_placeholders() . '</span>' . "\r\n";
$listing_template .= "\t\t\t\t" . '<span class="wpsl-country"><%= country %></span>' . "\r\n";
$listing_template .= "\t\t\t" . '</p>' . "\r\n";
$listing_template .= "\t\t" . '</div>' . "\r\n";
I attempted the following solution, but unfortunately, it did not resolve the issue!
document.getElementById('street1').style.display = 'none';
UPDATE: Currently exploring options that avoid utilizing JavaScript since the file is predominantly PHP-based.