Jump to content

Recommended Posts

Hi,

 

I am new to php and trying to convert a wordpress form text box to a dropdown list, which then shows the value selected on a different page. I have the code and the text box showing but I do not know how to change the input form to have a dropdown.

 

I would like the dropdown to show the following values for "Condition"=:

 

New

Used

Other

 

The code for the page that the value displays on is as follows:

 

<?php echo $condition; ?>

 

 

This is the text form I need to change to a dropdown:

 

<li>

<h2><?php echo __('Condition', 'AuctionTheme'); ?>:</h2>

<p><input type="text" size="10" name="condition" class="do_input"

value="<?php echo get_post_meta($pid, 'condition', true); ?>" /> <?php do_action('AuctionTheme_step3_after_condition_field'); ?></p>

</li>

 

 

Can someone give me a clue in the right direction? thanks

Link to comment
https://forums.phpfreaks.com/topic/268965-converting-text-box-to-dropdown/
Share on other sites

  • 4 weeks later...

I think it will be like this

 

From

<input type="text" size="10" name="condition" class="do_input"

value="<?php echo get_post_meta($pid, 'condition', true); ?>" />

 

To

 

Suppose the value will be "Other"

 

<select>

<option value="<?php echo get_post_meta($pid, 'condition', true); ?>" selected="selected"><?php echo get_post_meta($pid, 'condition', true); ?></option>

<option value="New">New</option>

<option value="Ued">Used</option>

</select>

 

You need to put logic in the "selected" attribute whether if it's selected or not by using tertoary operator.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.