Results 1 to 3 of 3

Thread: asp-javascript

  1. #1
    Join Date
    Nov 2004
    Posts
    2

    Unanswered: asp-javascript

    I am creating many text boxes by doing:
    ---------------------
    <% for i=1 to 9 %>
    <INPUT TYPE="text" VALUE="5" NAME="dbh<%=i%>2">
    <% Next %>
    ---------------------
    and then in my javascript function I want to assign values to these text boxes;
    --------------------------
    for (s = 1; s <= 9; s++) {
    f="dbh"+s+"2"
    document.t3.f.value= s;
    }
    --------------------------
    but the above function does not work..
    I tried
    var tk="t3.dbh12";
    document[tk].value;

    but that does not work either!
    Does anybody know how I can write the javascript function?

  2. #2
    Join Date
    May 2004
    Posts
    125
    Do a search for the javascript function eval. That will help you to create javascript that will access dynamic objects.

    http://builder.com.com/5100-6371-5169823.html

    HTH
    Jeff

  3. #3
    Join Date
    Aug 2004
    Posts
    96
    Hi,
    it looks like you are mixing up client side and server side javascript.
    If you want to build form elements dynamically you would use only server side javascript and html:

    <%//server side javascript
    //loop and create a text field on each loop

    //declare the f variable and store the new field name for each loop
    var f;

    for (s = 1; s <= 9; s++) {
    //change the name of f at each loop
    f="dbh"+s+"2";
    //now we are ready to build the html, lets close the server side asp tag and switch to html

    %>

    <p><INPUT TYPE="text" VALUE="value goes here" NAME="<% = f %>"></P>

    <%
    //now we are back server side and close the loop
    }
    //end of script

    %>

    This should do it, not that you should do this within the body of your page where you want to form elements to go.
    Hope this helps,
    Regards,

Posting Permissions

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