Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7679515
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T17:53:43+00:00 2026-05-31T17:53:43+00:00

I have a drop down menu of mobile brands. When a user selects a

  • 0

I have a drop down menu of mobile brands. When a user selects a mobile brand a dynamic drop populates with the mobile model according to the mobile brand I want to validate that mobile model drop down for a blank select value. I am using ajax xmlhttp request for getting the mobile model drop down menu.

My entire code is:

Code for page with mobile brand drop down menu

<script type="text/javascript">
    function validate() {
        if (document.myform.step3_mobilebrand.value=="") {
            document.getElementById("error1").innerHTML = (error1) ? "<img src='images/formerror.gif' height='15' width='18'>" : "";
            document.myform.step3_mobilebrand.focus();
            return false;
        }

        var myTextField = document.myform.getElementById('step3_mobilemodel').value;

        if (myTextField == "") {
            document.getElementById("error2").innerHTML = (error2)?"<img src='images/formerror.gif' height='15' width='18'>" : "";
            document.myform.step3_mobilemodel.focus();
            return false;
        }


    }
</script>

<?php
if (isset($_POST['submitted']) and $_POST['submitted']=="Continue") {
    $mobilebrand1 = $_POST['step3_mobilebrand'];
    $mobilemodel1 = $_POST['step3_mobilemodel'];

    if ($mobilemodel1=="") {
        echo "Please Select Mobile Model";          
    }

    $connectiontype=$_POST['step3_connectiontype'];
    $internet=$_POST['step3_internet'];

    include("admin/config.php");

    $sql="insert into member_detail (mobilebrand,mobilemodel,connection_type,internet) values('$mobilebrand1','$mobilemodel1','$connectiontype','$internet')";

    mysql_query($sql);
}
?>

<script type="text/javascript">
function showUser(str) {
    if (str=="") {
        document.getElementById("txtHint").innerHTML="";
        return;
    } 

    if (window.XMLHttpRequest) {// code for IE7+, Firefox, Chrome, Opera, Safari
        xmlhttp=new XMLHttpRequest();
    } else {// code for IE6, IE5
        xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
    }

    xmlhttp.onreadystatechange=function() {
        if (xmlhttp.readyState==4 && xmlhttp.status==200) {
            document.getElementById("txtHint").innerHTML=xmlhttp.responseText;
        }
    }

    xmlhttp.open("GET","getuser.php?q="+str,true);
    xmlhttp.send();
}
</script>

<form name="myform" method="post" action="" onsubmit="return validate();">
    <table>
        <tr>
            <td>Mobile Brand</td>
            <td><?php 
                include ("admin/config.php");
                echo "<select name='step3_mobilebrand' onchange='showUser(this.value)'><option value='' selected>Select Mobile Brand</option>";
                $result = mysql_query ("select * from mobilebrand order by mobilebrand");
                while ($adcom=mysql_fetch_array($result)) {
                    echo "<option value=\"".$adcom['id']."\">".htmlspecialchars($adcom['mobilebrand'])."</option>";
                }

                echo "</select>";?><span id="error1" style="color:red;"></span></td>

        </tr>
    </table>
    <div id="txtHint"></div>
    <table>
        <tr>
            <td>Connection Type</td>
            <td><input type="radio" name="step3_connectiontype" value="PrePaid" checked="checked">Prepaid
                <input type="radio" name="step3_connectiontype" value="PostPaid">Postpaid
                <span id="error3" style="color:red;"></span>
            </td>
        </tr>
        <tr>
            <td>Have Internet On Mobile</td>
            <td><input type="radio" name="step3_internet" value="Yes" checked="checked">Yes
                <input type="radio" name="step3_internet" value="No">No
                <span id="error4" style="color:red;"></span>
            </td>
        </tr>
        <tr>
            <td></td>
            <td><input type="submit" name="submitted" value="Continue"></td>
        </tr>
    </table>
</form>

and the code of getuser.php is

<table>
    <tr>
        <td>Mobile Model</td>
        <td>
            <?php
            $q=$_GET["q"];
            include("admin/config.php");
              echo "<select name='step3_mobilemodel' id='step3_mobilemodel' ><option value=''>Select Mobile Model</option>";
            $result = mysql_query ("select * from mobilemodel where brandcode='".$q."'");
            while ($adcom=mysql_fetch_array($result)) {
                echo "<option value=\"".$adcom['mobilemodel']."\">".htmlspecialchars($adcom['mobilemodel'])."</option>";
            }
                echo "</select>"; ?>

        </td>
    </tr>
</table>

The Output am getting is correct i just want to validate the mobile model drop down menu for blank select

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-31T17:53:44+00:00Added an answer on May 31, 2026 at 5:53 pm

    For validating select you can do:

    
    var e = document.getElementById("step3_mobilemodel");
    var mobileVal = e.options[e.selectedIndex].value;
    if(mobileVal == "") {
      ...//show your error here
    }
    

    Hope it helps

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to have a drop down menu where a user can select from
I have a drop down menu with css file and i want to convert
I have a drop down menu in my html, and what I want is
I have this drop down menu.It stores month, Jan-Dec. User can choose any value
I have a drop down menu using CSS only. I want the drop down
My problem is: I have a drop down menu and i want that when
I have a drop down menu and it works perfectly on everything except IE6
I have a drop down menu in an ASPX page along the lines of:
I have a drop down menu made with Jquery. Right now, if you hover
We have a drop-down menu of volumes in our UI, and I'd like to

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.