Auto Populate Form

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • tsubasa
    New Member
    • Aug 2008
    • 64

    Auto Populate Form

    I have a form in ASP.net that has a checkbox option to auto populate the form with the user infomation that is held in an table. When I select the checkbox the auto populate works well with texboxes in the form, but the auto populate does not work completely because a field in the form called shipcamp uses a dropdown list. How can I auto populate the camp field dropdown list as well using JavaScript? Thank you!

    -Tsu

    -----JAVASCRIPT--------
    Code:
    %>
    <!--#include file="../includes/top.asp"-->
    <script language="JavaScript">
    <!-- Function for auto-complete shipping address!
    function fillAddressFields(form) {
        form.elements['shipgrade'].value = '<%=grade%>';
        form.elements['shipfname'].value = '<%=fname%>';
        form.elements['shiplname'].value = '<%=lname%>';
        form.elements['shipunit'].value = '<%=organization%>';
        form.elements['shipbldg_no'].value = '<%=bldg_no%>';
        form.elements['shipphone'].value = '<%=phone_no%>';
        form.elements['firstsigner'].value = '<%=asigner1%>';
        form.elements['shipcamp'].text = '<%=camp%>';
        form.elements['shipdirections'].value = '<%=directions%>';
        form.elements['shipphone1'].value = '<%=asigner1phone%>';
    }
    //-->
    Last edited by gits; Mar 11 '10, 11:02 AM. Reason: added code tags
  • gits
    Recognized Expert Moderator Expert
    • May 2007
    • 5390

    #2
    you would just need to set the value ... not text ... i assume your select node's options have values assigned?

    Comment

    • tsubasa
      New Member
      • Aug 2008
      • 64

      #3
      I have tried the value initially, but it did not work. As you can see from the posting that I have also tried text, but to no avail. Any suggestions?

      Comment

      • gits
        Recognized Expert Moderator Expert
        • May 2007
        • 5390

        #4
        does your option nodes have a value attribute?

        here is a short working example:

        Code:
        <html>
        <body onload="document.getElementById('foo').value = '2';">
        <select id="foo">
            <option value="1">1</option>
            <option value="2">2</option>
            <option value="3">3</option>
        </select>
        </body>
        </html>

        Comment

        • tsubasa
          New Member
          • Aug 2008
          • 64

          #5
          Hi,

          No it does not, let me try it with the attribute.

          -Tsu

          Comment

          • gits
            Recognized Expert Moderator Expert
            • May 2007
            • 5390

            #6
            as you might see from the example above ... with the value attribute it should work ... and to be able to set the value values need to be present :) ... otherwise you would need to implement a logic that loops through the options and set the selected attribute which of course would be a possibility but even a bit of overhead ... basicly you should always have values for option nodes since this is much better to handle when you have special validation tasks or whatever ... if you would rely on text then you would need to have much more logic when it comes to multilanguage apps etc. since the text would be changing according to the languages while the values doesn't ...

            kind regards

            Comment

            Working...