Results 1 to 3 of 3
Jan 5, 2012, 00:12 #1
- Join Date
- Dec 2011
- 0 Post(s)
- 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
Jan 5, 2012, 15:26 #2
- Join Date
- Jan 2007
- Christchurch, New Zealand
- 61 Post(s)
- 3 Thread(s)
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
The 2013 SitePoint Awards - Nominate your heroes now!
Jan 5, 2012, 15:49 #3
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