[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Changing a dropdowns contents with php

Posted on 2005-05-09
2
Medium Priority
?
185 Views
Last Modified: 2006-11-18
I have a form with a dropdown as follows:

<select name="myDropdown" id="lisAnalogue" onchange='submit()'>
 <option value = '1' <?php if (isset($_POST['myDropdown']) && $_POST['myDropdown'] == "1") echo "selected"; ?>>1</option>
 <option value = '2' <?php if (isset($_POST['myDropdown']) && $_POST['myDropdown'] == "2") echo "selected"; ?>>2</option>
 </select>

However if a certain value is chosen on another dropdown on the same form I need only the value of 1 to appear in myDropdown after the refresh ie

<select name="myDropdown" id="lisAnalogue" onchange='submit()'>
<option value = '1' <?php if (isset($_POST['myDropdown']) && $_POST['myDropdown'] == "1") echo "selected"; ?>>1</option>
 </select>

How can I achieve this using php??

Many thanks
0
Comment
Question by:kenabbott
2 Comments
 
LVL 20

Expert Comment

by:virmaior
ID: 13962220
normally you would just do this do JavaScript

<SCRIPT Language="JavaScript">

function onmychange()
{
   document.getElementById("lisAnalogue").options[1] = null;
}
</SCRIPT>

where onmychange() gets called when the value is set on other dropdown..

0
 
LVL 32

Accepted Solution

by:
ldbkutty earned 1000 total points
ID: 13962589
Disable the select menu so it defaults to the first option. Ex:

<select name="myDropdown" id="lisAnalogue" onchange='submit()'>
 <option value = '1' <?php if (isset($_POST['myDropdown']) && $_POST['myDropdown'] == "1") echo "selected"; ?>>1</option>
 <option value = '2' <?php if (isset($_POST['myDropdown']) && $_POST['myDropdown'] == "2") echo "selected"; ?>>2</option>
</select>

<select name="myDropdown2" id="lisAnalogue2" onchange='this.form.myDropdown.disabled=true; submit()'>
<!-- Your options here -->
</select>

// Or make the selection of myDropdown to first option while submitting, Ex. : this.form.myDropdown.selectedIndex=0;
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Build an array called $myWeek which will hold the array elements Today, Yesterday and then builds up the rest of the week by the name of the day going back 1 week.   (CODE) (CODE) Then you just need to pass your date to the function. If i…
Since pre-biblical times, humans have sought ways to keep secrets, and share the secrets selectively.  This article explores the ways PHP can be used to hide and encrypt information.
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…
Suggested Courses
Course of the Month18 days, 18 hours left to enroll

834 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question