Results 1 to 9 of 9

Thread: Javascript help needed!!

  1. #1
    MarcelB
    Guest

    Exclamation

    Hi everyone!

    I have an input page on which I have a few selectboxes, each with the same name, but a different value. The selectboxes are placed on the page using an include file. After placing the boxes, I want to make a few of the options checked, but since they are already in my page, I need to use Javascript for that.

    I have tried different ways, but none has worked yet. Any ideas?

    I have the value of the option I want to have checked in a variable called TheseNeedToBeChecked. These are some of the ways I tried:

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

    var CheckThisOne = <%= TheseNeedToBeChecked %>;

    myform.hobbies(CheckThisOne).selected = true;
    myform.hobbies[CheckThisOne].selected = true;
    myform.hobbies(CheckThisOne).selected;
    myform.hobbies[CheckThisOne].selected;

    myform.hobbies(CheckThisOne).checked = true;
    myform.hobbies[CheckThisOne].checked = true;
    myform.hobbies(CheckThisOne).checked;
    myform.hobbies[CheckThisOne].checked;

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

    Any help would be highly appreciated.

    Marcel

  2. #2
    Addicted Member Active's Avatar
    Join Date
    Jan 2001
    Location
    Lat: 13° 4' 46" N, Long: 80° 15' 20" E
    Posts
    209
    Did you mean you want some of the options in the
    Select box Selected by default ?
    If you can't beat your computer at chess, try kickboxing !!!
    [Download Tag Editing Tools.]

  3. #3
    Guest
    yes.

  4. #4
    Frenzied Member Mark Sreeves's Avatar
    Join Date
    Nov 1999
    Location
    UK
    Posts
    1,845
    can you post/mail what you've got so far so I don't have to code an example from scratch?
    Mark
    -------------------

  5. #5
    Guest

    All I got?

    What do you mean "what I got"?

    I have all the code, I only need the one line (I hope it's one line anyway) to get the checkbox checked. And when I say checked, I mean so that the "V" is in it, indicating the value is "on".

    So the code I have so far is like this:
    (the value "Hobbies" in the recordset UserData contains the indexes of the checkboxes I want to have checked, seperated by ";")

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

    dim strHobbies
    strHobbies = UserData("Hobbies")
    dim intInPos
    intInPos = instr(strHobbies, ";")
    dim strHobbyName
    dim intIntHobbyID
    do while intInPos <> 0
    intIntHobbyID = cint(left(strHobbies, intInPos - 1))%>

    <script language="javascript">
    var HobbyID2Check = <%= intIntHobbyID %>;
    myform.hobbies[HobbyID2Check].checked = true;
    </script>

    <%strHobbies = right(strHobbies, len(strHobbies) - intInPos)
    intInPos = instr(strHobbies, ";")
    loop%>

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

    Hmm.. I see now that I will probably also need to process the last value (when there is just the value left in the string, and no more semi-colons)

    Hope you can help. Thanx in advance.

    Marcel

  6. #6
    Guest
    For checking a Checkbox you can use this syntax.
    Code:
    // JavaScript, Setting the checkbox on
    Checkbox.checked = 1;

  7. #7
    Frenzied Member Mark Sreeves's Avatar
    Join Date
    Nov 1999
    Location
    UK
    Posts
    1,845
    OK, I can't see where on your page the include for writing the check boxes is so I've assumed it is between the body tags.
    Here's what I've got anyway.

    ch.js
    Code:
    document.write("<form name=frm1>");
    
    document.write("<input name=hobbies type=checkbox> zxdfgh</input><BR>");
    document.write("<input name=hobbies type=checkbox> hgfdhsdfh</input><BR>");
    document.write("<input name=hobbies type=checkbox> ryqreyr</input><BR>");
    document.write("<input name=hobbies type=checkbox> cxzvbczvxb</input><BR>");
    
    document.write("</form>");
    ch.asp
    Code:
    <%@ Language=VBScript %>
    <html>
    
    <head>
    <% dim x
    
    x=2
    
    %>
    
    <script LANGUAGE="JavaScript">
    function init(){
    
    document.frm1.hobbies[<%=x%>].checked= true   
    
    }
    </SCRIPT>
    
    </head>
    
    <body onload="init()">
    
    <script language="JavaScript"
    SRC="ch.js">
    </SCRIPT>
    
    </body>
    </html>
    is this any help?
    Mark
    -------------------

  8. #8
    Guest
    Well, not really, coz that wasn't really what I meant..

    But for some reason, now all of a sudden, it seems to work (after I realised it used the index instead of the ID of the checkbox to check). I also adjusted the code so it takes care of that last item aswell.

    So it works now.
    Thanx, guys..

  9. #9
    Guest
    Well, not really, coz that wasn't really what I meant..

    But for some reason, now all of a sudden, it seems to work (after I realised it used the index instead of the ID of the checkbox to check). I also adjusted the code so it takes care of that last item aswell.

    So it works now.
    Thanx, guys..

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