SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Member
    Join Date
    Dec 2011
    Posts
    17
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    It displays a textbox with value 1 but it should display a string instead

    If the user selects the option True or False and adds it into a new row, it displays a textbox with the value 1, it should instead display a string stating "Only 1 Answer" with a hidden textbox that contains the value 1.
    I don't know why it is doing this. The other options 3, 4 and 5 will display a textbox for Number of Answers but True or False should display "Only 1 Answer" in the new added row.

    Follow the steps below in my fiddle to use the application and to test your code in the application:

    Step 1: Open the grid and select option 3. Below the option textbox it will display a textbox with the number 0 in it.

    Step 2: Click on the "Add Question" button, this will add the details from the top into a new row below. As you can see under the "Number of Answers" column in you new row it displays the textbox with the value 0 from above.

    Step 3. Now go back to the top control and open the grid again but this time select the option "True or False". You will see below it displays the string "Only 1 Answer"

    Step 4: Now click on "Add Question". This is where the problem occurs. It will add a new row but instead of displaying "Only 1 Answer" under the "Number of Answer" column within the row you
    have just added, it displays a textbox with the value 1. This is incorrect, it should display the string "Only 1 Answer" and there should be a hidden textbox which contains the value 1.

    Can anyone solve this problem? Please use the fiddle to test my code and to show a working example.

    Code in jsfiddle, click here

  2. #2
    Unobtrusively zen silver trophybronze trophy
    paul_wilkins's Avatar
    Join Date
    Jan 2007
    Location
    Christchurch, New Zealand
    Posts
    14,526
    Mentioned
    83 Post(s)
    Tagged
    3 Thread(s)
    Quote Originally Posted by sachinmaster View Post
    Please use the fiddle to test my code and to show a working example.
    To show a working example? This is not a school lesson where the teacher hands out assignments.

    You can easily solve this issue in a number of different ways.

    A simple way is to check if the value is '1', and then split off in to an if/else situation where different behaviour occurs.
    That tends to result though in duplicated code in each block of the if/else structure.

    Another fairly simple way is to use a variable to store an empty span and the input type of 'text'
    That way you can check if the value is '1' and if it is, you add the 'only 1 answer' part to the span, and set the text to be 'hidden'

    Please use your fiddle to try out different variations of the above, and see if you can come up with a working example.
    Programming Group Advisor
    Reference: JavaScript, Quirksmode Validate: HTML Validation, JSLint
    Car is to Carpet as Java is to JavaScript

  3. #3
    Non-Member Max Height's Avatar
    Join Date
    Dec 2011
    Posts
    303
    Mentioned
    6 Post(s)
    Tagged
    1 Thread(s)
    Quote Originally Posted by sachinmaster View Post
    Please use the fiddle to test my code and to show a working example.
    I agree with paul_wilkins and this forum is not a classroom where you, "the teacher", hands out "homework" to everyone else ("the students") .

    If you're not getting syntax errors then you have logic errors in your code you need to find and fix. There are several ways to do that, some of which have already been mentioned. Other ways include using a debugger (like Firebug) or just plain old alert() statements to check variables' values and code logic.

    If you want to take coding seriously then you will need to develop your own debugging techniques and skills otherwise you will forever be floating around forums handing out "homework" to hopefully get someone to fix your stuff ups


Tags for this Thread

Bookmarks

Posting Permissions

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