Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    New Coder
    Join Date
    Jan 2007
    Posts
    55
    Thanks
    0
    Thanked 0 Times in 0 Posts

    ASP in Javascript

    Hi there...I am trying to create a input form field with a value say " American Express". When user clicks on this field to edit it, it turns into a dropdown menu which is pulling all credit cards names from a database table....so users can choose an option from the menu....

    1) Is is too much hassle to achieve...I thought it might be kinda neat.

    2) Here's the code:

    <form name="CreditCardform" method="post" action="anaspppage.asp", target="main">

    <td><input name=CardType onclick="ShowDropDown();" Value="<%=CreditCardDetail("Description")%>"></td>

    </form>

    ========================================================

    <script language="JavaScript1.2"><!--
    function ShowDropDown()
    {
    <% mySQL = "SELECT * FROM CreditCardTypes order by code"
    Set CreditCardTypes= Con.Execute( mySQL )

    %>

    <td class=tabletd><select name=CardType class=fields>

    <option></option>
    <% do while CreditCardTypes.eof<>true %>

    <option <% if request("CardType")=CreditCardTypes("Description") then %>selected<% end if %> value='<%=CreditCardTypes("Code")%>'><%=CreditCardTypes("Description")%></option>

    <% CreditCardTypes.movenext
    loop

    CreditCardTypes.close
    set CreditCardTypes=Nothing%>

    <% end if %>

    </td>

    }
    // --></script>


    =======================================================

    The javascript is completely wrong coz I just copied it from the existing form but thats the idea of what a want to try...a drop down..maybe i should use document.Page.homephone.value=document.CreditCardform.CardType.value= something.....any clues????

  • #2
    Senior Coder
    Join Date
    Nov 2002
    Location
    North-East, UK
    Posts
    1,265
    Thanks
    0
    Thanked 0 Times in 0 Posts
    You need to look into use Ajax and not just javascript.

  • #3
    Supreme Master coder! glenngv's Avatar
    Join Date
    Jun 2002
    Location
    Philippines
    Posts
    11,047
    Thanks
    0
    Thanked 251 Times in 247 Posts
    Code:
    <script type="text/javascript">
    function showDropdown(ccTxtFld){
      var sel = ccTxtFld.form.ccSel;
      for (var i=0; i<sel.options.length;i++){
         if (sel.options[i].text == ccTxtFld.value){
            sel.selectedIndex = i;
            break;
         }
      }
      sel.style.display = "inline";
      ccTxtFld.style.display = "none";
      sel.focus();
    }
    
    function showText(ccSelect){
      var ccTxtFld = ccSelect.form.ccTxt;
      ccTxtFld.value = ccSelect.options[ccSelect.selectedIndex].text;
      ccTxtFld.style.display = "inline";
      ccSelect.style.display = "none";
    }
    </script>
    ...
    <form>
    <input type="text" name="ccTxt" onfocus="showDropdown(this)" value="<%=CreditCardDetail("Description")%>" /><select name="ccSel" style="display:none;" onchange="this.blur();" onblur="showText(this)">
    <option></option>
    <%
    mySQL = "SELECT * FROM CreditCardTypes order by code" 
    Set CreditCardTypes= Con.Execute( mySQL )
    do while CreditCardTypes.eof<>true 
    %>
    
    <option <% if request("CardType")=CreditCardTypes("Description") then %>selected<% end if %> value="<%=CreditCardTypes("Code")%>"><%=CreditCardTypes("Description")%></option>
    
    <% CreditCardTypes.movenext
    loop
    
    CreditCardTypes.close
    set CreditCardTypes=Nothing
    %>
    
    </select>
    </form>


  •  

    Posting Permissions

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