Skip to content
View in the app

A better way to browse. Learn more.

Web Designer Forum

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

repeatable select boxes

Featured Replies

I'm trying to create repeatable select boxes (on the Wordpress admin page) and having a bit of a problem. It seems my i++ is not working and I am only able to save a single value. I didn't include the variable definations but I think they are fairly self-explanitory.

 

case 'home_player_list':
			echo '<a class="repeatable-add button" href="#">+</a>
                <ul id="'.$field['id'].'-repeatable" class="custom_repeatable">';
			$post_id = get_the_ID();
			$team_id = get_post_meta( $post_id, 'report_home-select');

			$items = get_users( array (
					'meta_key' => 'team-meta',
					'meta_value' => $team_id
				));
			$i = 0;
			if ($meta) {
				foreach($meta as $row) {
					echo '<li><span class="sort hndle button">|||</span>';
					echo '<select name="'.$field['id'].'['.$i.']" class="chzn-select" style="width:200px;" id="report_home-scorers">
			        <option value="">Select One</option>'; // Select One
					foreach($items as $item) {
						echo '<option value="'.$item->ID.'"',$meta == $item->ID ? ' selected="selected"' : '','>'.$item->display_name.'</option>';
					}
					echo '</select><a class="repeatable-remove button" href="#">-</a></li>';

					$i++;
				}
			} else {
				echo '<li><span class="sort hndle button">|||</span>';
				echo '<select name="'.$field['id'].'['.$i.']" class="chzn-select" style="width:200px;" id="'.$field['id'].'">
                <option value="">Select One</option>'; // Select One

				foreach ($items as $item) {
					echo '<option value="'.$item->ID.'"',$meta == $item->ID ? ' selected="selected"' : '','>'.$item->display_name.'</option>';
				}

				echo '</select><a class="repeatable-remove button" href="#">-</a></li>';

			}
			echo '</ul><span class="description">'.$field['desc'].'</span>';
			break;

It works just fine when I use an imput field but I can't save more than one value in an array. What I'm aiming for is an array of id numbers. If anyone can see offhand what I've done wrong, I'd be very grateful.

  • Author

In case anyone is curious:

 

Turns out my javascript needed fixing. I was cloning the field and not incrementing it correctly. Also I had

 

$meta == $item->ID ? ' selected="selected"' :

 

instead of $row == $item->ID ? ' selected="selected"' :

Create an account or sign in to comment

Account

Navigation

Search

Search

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.