Results 1 to 5 of 5

Thread: document.write?

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Feb 1999
    Location
    Belfast
    Posts
    254
    Hi,
    I have a novices question. I have a list box control which when selected hunts through a client side array and if it finds a match ( its supposed to ) write contents of the array element to the SAME page.

    the only way I have been able to do this so far is with a textarea. Is there a way to write the contents of the client array element below mt control, document.write appears to create a new page.

    So I have initially

    Company A
    Company B
    Company C
    Company D

    If someone clicks on "Company A" then details of Company A are listed below the listbox control


    Thanks in advance.

    Lenin


  2. #2
    New Member
    Join Date
    Jan 2001
    Location
    Coimbatore
    Posts
    7
    If you are using ASP,

    then u can write the code like this.

    The following code should be of before the HTML Code


    <%
    Response.write("<SCRIPT language=javascript>")
    'To Create New Array
    Response.Write("var state=new Array();")

    'Function Starting
    Response.Write("function f1(){")


    'Creating Default for State
    Response.Write("form1.selState.options[0]=new Option('- - Select a State - -',-1);")

    dim i,loc,cn,rs,j
    set cn=server.CreateObject("adodb.connection")
    set rs=server.CreateObject("adodb.recordset")
    cn.open "Provider=SQLOLEDB.1;Password=studies;Persist Security Info=True;User ID=studies;Initial Catalog=studies;Data Source=cgvak84"
    set rs=cn.Execute("Select * from cgvak_edport_location order by loc_loc_icode")

    i=-1
    j=1
    loc=0

    Response.Write("state[" & i+1 & "]=new Array();")

    while not rs.EOF

    if clng(loc)<> clng(rs.Fields("loc_loc_icode")) then
    j=0
    i=i+1
    loc=rs.Fields("loc_loc_icode")
    'To Create a Two Dimensional Array
    Response.Write("state[" & i & "]=new Array();")

    'To Store the Country Icode in the 0th Element [0][0]
    Response.Write("state[" & i & "][" & j & "]='" & rs.Fields("loc_loc_icode") & "';") j=j+1

    'To Store the State Icode and Name
    Response.Write("state[" & i & "][" & j & "]='" & rs.Fields("loc_icode") & "|" & rs.Fields("loc_name") & "';")

    j=j+1
    else

    response.Write("state[" & i & "][" & j & "]='" & rs.Fields("loc_icode") & "|" &
    rs.Fields ("loc_name") & "';")
    j=j+1
    end if
    rs.MoveNext
    wend
    rs.close
    set rs=nothing
    %>


    }
    </script>

    <script language=javascript >


    function selCountry_onchange()
    {
    var i,len,len1,hidval
    if (form1.selCountry.value==-1)
    {
    toRemove();
    form1.selState.options[0]=new Option('- - Select a State - -',-1);
    return;
    }
    len=state.length;

    for (i=0;i<len;i++)
    {

    if (state[i][0]==form1.selCountry.options[form1.selCountry.selectedIndex].value)
    {

    toRemove();

    for (j=0;j<state[i].length;j++)
    {
    if (j==0)
    {
    form1.selState.options[0]=new Option('- - Select a State - -',-1);
    }
    else
    {
    sp=state[i][j].split("|");
    form1.selState.options[j]=new Option(sp[1],sp[0]);
    }
    }

    }
    }
    }

    function toRemove()
    {
    len=form1.selState.length;
    for(k=0;k<=len;k++)
    {
    form1.selState.remove(0);
    }
    }

    //-->
    </SCRIPT>

    <html>
    <body onload=f1()>

    </body>
    </html>

  3. #3

    Thread Starter
    Addicted Member
    Join Date
    Feb 1999
    Location
    Belfast
    Posts
    254
    No, sorry I should have explained in more detail, I don't want another trip to the server. I have already populated an array on the client to avoid another trip.

    Lenin

  4. #4
    Frenzied Member Mark Sreeves's Avatar
    Join Date
    Nov 1999
    Location
    UK
    Posts
    1,845
    I think you can do it with layers but I'm not over-familiar with writing to layers and it's awkard making it cross-browser compatable.

    One thing I did was to have all the javascript in a page in a hidden frame which then wrote javascript and the current output to the main frame.

    This was mind numbing though because the javascipt in the "control" page has being written dynamically using server-side javascript.
    This meant I had three "levels" of javascript:

    Server-side JavaScript writing client-side JavaScipt to write Client-side JavaScript in another page. AAAARRRGGHHH!

    works well though!
    Mark
    -------------------

  5. #5

    Thread Starter
    Addicted Member
    Join Date
    Feb 1999
    Location
    Belfast
    Posts
    254
    Yes,
    the server side JavaScript for client, this is what I was using in the first instance, populating array on server passing back to client, bit of a nightmare, and looks very dirty, but as you say, works ok.

    Thanks Mark.

    Lenin

Posting Permissions

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



Click Here to Expand Forum to Full Width