SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Guru
    Join Date
    Feb 2006
    Location
    Chepstow, South Wales
    Posts
    906
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    On select of choice form drop down check database for ID then add 1 and use

    I have a drop down that is automatically generated using PHP, and basically what I need to happen is on selection of a ceratin one to go to the database and check the latest id associated with that category and the use that ID add 1 to it, and then when the user updates the database, the new ID is associated with that entry.

    I was htinking that AJAX might be the best option for it.

    Here is what I got so far.

    Code:
    <
    select name="txtdesc">
    <?php $qw=mysql_query("select DISTINCT(Desc_Ame), Id_Ame from tbl_amenities group by Desc_Ame") or die (mysql_error());
    while($r=mysql_fetch_assoc($qw))
    {
    if($r['Desc_Ame']==$desc)
    {
    echo "<option value='$r[Desc_Ame]' selected>$r[Desc_Ame]</option>";
    }
    else
    {
    echo "<option value='$r[Desc_Ame]'>$r[Desc_Ame]</option>";      
    }
    }
    ?>

  2. #2
    SitePoint Guru
    Join Date
    Feb 2006
    Location
    Chepstow, South Wales
    Posts
    906
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    OK I found an idea and am trying to apply it to this job, and what I thought would happen isnt, so I'm missing something somewhere.

    Code:
    <script type="text/javascript">
    function showUserGroup(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","getusergroup.php?q="+str,true);
        xmlhttp.send();
    }
    </script>
    
    <script type="text/javascript" src="https://ajax.googleapis.com/ajax/lib...n.js"></script>
    
    <script type="text/javascript">
    $('[name="form1"]').on('change', function() {
        var ajaxMethod = "admin_amenties.php";
        switch($(this).val())
        {
        case "General":
          ajaxMethod = "stuff 1";
          break;
        case "Rooms":
          ajaxMethod = "stuff 2";
          break;                
        case "Services":
          ajaxMethod = "stuff 3";
          break;                
        case "Meeting":
          ajaxMethod = "stuff 4";
          break;
     case "Accessibility":
          ajaxMethod = "stuff 5";
          break;      
       }
       $("#txtHint b").load(ajaxMethod);
    });​
    </script>
    
    
    <form action="admin_amenties.php?index=<?=$index?>" method="post" name="form1" onchange="showUserGroup(this.value)">
    <select name="txtdesc">
    <?php $qw=mysql_query("select DISTINCT(Desc_Ame), Id_Ame from tbl_amenities group by Desc_Ame") or die (mysql_error());
    while($r=mysql_fetch_assoc($qw))
    {
    if($r['Desc_Ame']==$desc)
    {
    echo "<option value='$r[Desc_Ame]' selected>$r[Desc_Ame]</option>";
    }
     else
    {
    echo "<option value='$r[Desc_Ame]'>$r[Desc_Ame]</option>";      
    }
    }
    ?>
    </select>
    <div id="txtHint"></div>
    </form>

  3. #3
    Unobtrusively zen silver trophybronze trophy
    paul_wilkins's Avatar
    Join Date
    Jan 2007
    Location
    Christchurch, New Zealand
    Posts
    14,678
    Mentioned
    99 Post(s)
    Tagged
    4 Thread(s)
    It looks like you are inappropriately loading jQueryUI.
    What should work much better for you here it to load up the jQuery library instead.
    Programming Group Advisor
    Reference: JavaScript, Quirksmode Validate: HTML Validation, JSLint
    Car is to Carpet as Java is to JavaScript


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •