Connect with Expertise | Find Experts, Get Answers, Share Insights

Auto Populate Form

tsubasa's Avatar  
Join Date: Aug 2008
Posts: 43
#1: Mar 10 '10
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--------
Expand|Select|Wrap|Line Numbers
  1. %>
  2. <!--#include file="../includes/top.asp"-->
  3. <script language="JavaScript">
  4. <!-- Function for auto-complete shipping address!
  5. function fillAddressFields(form) {
  6.     form.elements['shipgrade'].value = '<%=grade%>';
  7.     form.elements['shipfname'].value = '<%=fname%>';
  8.     form.elements['shiplname'].value = '<%=lname%>';
  9.     form.elements['shipunit'].value = '<%=organization%>';
  10.     form.elements['shipbldg_no'].value = '<%=bldg_no%>';
  11.     form.elements['shipphone'].value = '<%=phone_no%>';
  12.     form.elements['firstsigner'].value = '<%=asigner1%>';
  13.     form.elements['shipcamp'].text = '<%=camp%>';
  14.     form.elements['shipdirections'].value = '<%=directions%>';
  15.     form.elements['shipphone1'].value = '<%=asigner1phone%>';
  16. }
  17. //-->
  18.  
best answer - posted by gits
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

gits's Avatar
E
M
C
 
Join Date: May 2007
Location: Munich, Germany
Posts: 4,626
#2: Mar 11 '10

re: Auto Populate Form


you would just need to set the value ... not text ... i assume your select node's options have values assigned?
tsubasa's Avatar  
Join Date: Aug 2008
Posts: 43
#3: Mar 13 '10

re: Auto Populate Form


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?
gits's Avatar
E
M
C
 
Join Date: May 2007
Location: Munich, Germany
Posts: 4,626
#4: Mar 13 '10

re: Auto Populate Form


does your option nodes have a value attribute?

here is a short working example:

Expand|Select|Wrap|Line Numbers
  1. <html>
  2. <body onload="document.getElementById('foo').value = '2';">
  3. <select id="foo">
  4.     <option value="1">1</option>
  5.     <option value="2">2</option>
  6.     <option value="3">3</option>
  7. </select>
  8. </body>
  9. </html>
  10.  
tsubasa's Avatar  
Join Date: Aug 2008
Posts: 43
#5: Mar 18 '10

re: Auto Populate Form


Hi,

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

-Tsu
gits's Avatar
E
M
C
 
Join Date: May 2007
Location: Munich, Germany
Posts: 4,626
#6: Mar 19 '10

re: Auto Populate Form


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
Reply

Tags
populate form