Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 8 of 8
  1. #1
    New Coder
    Join Date
    Aug 2002
    Location
    india
    Posts
    74
    Thanks
    0
    Thanked 0 Times in 0 Posts

    can u solve my problem in javascript?

    sir, i have a problem in javascript. my problem looks like this
    in the html page assume inputbox,textbox etc in the place of words:
    (mc-multiplechoice,fg-fill in the gaps)

    Topic Name: inputbox1(values:c,c++,vb)

    Question Type: inputbox2(values:mc,fg)

    Question: textarea

    Answer : textarea

    choice1 : textbox1

    choice2 : textbox2

    choice3 : textbox3

    choice4 : textbox4

    my problem is i should be able to display only the "Answer" field if i select "fg" from inputbox2 and choices 1 through 4 should be displayed when "mc" is selected(i.e Answer field should not be displayed).can u clarify me this in javascript?
    phani

  • #2
    Senior Coder
    Join Date
    Aug 2002
    Posts
    3,467
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Are you familiar with the display style property? That, along with some events will get done what you need.

  • #3
    New to the CF scene
    Join Date
    Aug 2002
    Posts
    9
    Thanks
    0
    Thanked 0 Times in 0 Posts
    in more detail, you need to
    1) add to the select tag so that it looks like
    <SELECT OnChange="display_correct(this);"> ... options.. </SELECT>

    2) add some script like this
    <SCRIPT language="javascript"><!--
    function displaycorrect(obj)
    {
    if (obj.value=="mc")
    {
    textareaname.style.display="none";
    textbox1name.display="inline";
    textbox2name.display="inline";
    ....
    }
    else
    {
    textareaname.style.display="inline";
    textbox1name.display="none";
    ....
    }
    }

  • #4
    Senior Coder
    Join Date
    Jun 2002
    Posts
    1,404
    Thanks
    2
    Thanked 32 Times in 32 Posts

    <html>
    <head>
    <title>untitled</title>
    <script type="text/javascript" language="javascript">

    function getElement(id) {
    return document.getElementById ? document.getElementById(id) :
    document.all ? document.all(id) : null;
    }

    function toggle_display(val) {
    var el = getElement('txt_answer');
    if (el && el.style) el.style.display = (val == 'fg') ? '' : 'none';
    var el = getElement('txt_choose');
    if (el && el.style) el.style.display = (val == 'mc') ? '' : 'none';
    }

    </script>
    </head>
    <body>
    <form>
    <select name="inputbox1">
    <option selected="selected">Topic Name</option>
    <option value="c">c</option>
    <option value="c++">c++</option>
    <option value="vb">vb</option>
    </select>
    <br>
    <select name="inputbox2"
    onchange="toggle_display(this[this.selectedIndex].value)">
    <option selected="selected">Question Type</option>
    <option value="mc">multiple choice</option>
    <option value="fg">fill in the gaps</option>
    </select><br>
    Question: <br>
    <textarea name="question" rows="8" cols="64" wrap="virtual"></textarea>
    <div id="txt_answer" style="display:none;">
    Answer: <br>
    <textarea name="answer" rows="8" cols="64" wrap="virtual"></textarea>
    </div>
    <div id="txt_choose" style="display:none;">
    <input type="text" name="choice1" value="choice1">
    <input type="text" name="choice2" value="choice2">
    <input type="text" name="choice3" value="choice3">
    <input type="text" name="choice4" value="choice4">
    </div>
    <br><input type="submit" value="DONE">
    </form>
    </body>
    </html>


  • #5
    New Coder
    Join Date
    Aug 2002
    Location
    india
    Posts
    74
    Thanks
    0
    Thanked 0 Times in 0 Posts

    javascript

    thank u sir, i have got it. can u please explain what this statement function is doing?

    return document.getElementById ? document.getElementById(id) :
    document.all ? document.all(id) : null;

    Is there any property by name "getElementById" in document?
    and what document.all meant for?
    phani

  • #6
    Supreme Master coder! glenngv's Avatar
    Join Date
    Jun 2002
    Location
    Philippines
    Posts
    11,043
    Thanks
    0
    Thanked 251 Times in 247 Posts

    Re: javascript

    adios used the shortcut for if else statement, which i think is called ternary operator.

    variable = (condition) ? valueIfTrue:valueIfFalse;

    in the case of his code, he tests if the browser is IE5+ or IE6+ which support document.getElementById, if not he tests if the browser is IE4 which support document.all and if not null is returned.




    Originally posted by phani
    thank u sir, i have got it. can u please explain what this statement function is doing?

    return document.getElementById ? document.getElementById(id) :
    document.all ? document.all(id) : null;

    Is there any property by name "getElementById" in document?
    and what document.all meant for?

  • #7
    New Coder
    Join Date
    Aug 2002
    Location
    india
    Posts
    74
    Thanks
    0
    Thanked 0 Times in 0 Posts

    javascript

    thank u sir, for all those who helped me. can u send me the website addresses which provide the indepth knowledge in javascript
    phani

  • #8
    New to the CF scene
    Join Date
    Aug 2002
    Posts
    9
    Thanks
    0
    Thanked 0 Times in 0 Posts


  •  

    Posting Permissions

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