4 Replies - 2318 Views - Last Post: 18 December 2013 - 11:05 AM

#1 vicbelien   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 3
  • Joined: 18-December 13

Survey with multiple answers

Posted 18 December 2013 - 03:20 AM

Hi all,

I'm fairly new at this, so it should be an easy one to solve. I've searched the internet and I'm not really finding any solutions. I've created a two page survey, with on each page 16 checkboxes. You can select multiple checkboxes on each page. On the third page you can review the answers and send it to your own e-mail adress.
I'm typing this in Mobione, a program to make apps on windows for multiple platforms.

Here's the code

phoneui.prePageTransition = function(currentScreenId, targetScreenId) {
	[color="#2E8B57"]//update result page3 before it is shown, this is the review screen of the color analysis[/color]
	if (/p3$/.test(targetScreenId)) {
	  updateSummary();
	}
	 
	return true;
}

Here is the main code... The problem is I don't get to see the values if I use checkboxes. When I use radio buttons it works, but I need the checkboxes. Also when I click e.g. checkbox 1, it will show it's value but the unchecked checkboxes appear as Undefined. I want those unchecked values to dissappear.

phoneui.documentReadyHandler = function() {
}
function updateSummary() {
	 
	
	  
	  var result = "";
	  [color="#2E8B57"]//schrijf tekst[/color]
	  result += "Kleurenanalyse" + "\n"
	  result += "Type: Lente" + "\n"
	  [color="#2E8B57"]//get page LenteSelectieScherm[/color]
	  result += "Topkleuren : " + $('input[name="checkbox1"]:checked').val() + "\n";
	  result -= $('input[name="checkbox1"]:unchecked').val() + "\n";
	  
	  result += $('input[name="checkbox2"]:checked').val()+ "\n";
	  result -= $('input[name="checkbox2"]:unchecked').val() + "\n";
	  
	  result += $('input[name="checkbox3"]:checked').val()+ "\n";
	  result -= $('input[name="checkbox3"]:unchecked').val() + "\n";
	  
	  result += $('input[name="checkbox4"]:checked').val()+ "\n";
	  result -= $('input[name="checkbox4"]:unchecked').val() + "\n";
	  
	  result += $('input[name="checkbox5"]:checked').val() + "\n";
	  result -= $('input[name="checkbox5"]:unchecked').val() + "\n";
	  
	  result += $('input[name="checkbox6"]:checked').val()+ "\n";
	  result -= $('input[name="checkbox6"]:unchecked').val() + "\n";
	  
	  result += $('input[name="checkbox7"]:checked').val()+ "\n";
	  result -= $('input[name="checkbox7"]:unchecked').val() + "\n";
	  
	  result += $('input[name="checkbox8"]:checked').val()+ "\n";
	  result -= $('input[name="checkbox8"]:unchecked').val() + "\n";
	  
	  result += $('input[name="checkbox9"]:checked').val()+ "\n";
	  result -= $('input[name="checkbox9"]:unchecked').val() + "\n";
	  
	  result += $('input[name="checkbox10"]:checked').val()+ "\n";
	  result -= $('input[name="checkbox10"]:unchecked').val() + "\n";
	  
	  result += $('input[name="checkbox11"]:checked').val()+ "\n";
	  result -= $('input[name="checkbox11"]:unchecked').val() + "\n";
	  
	  result += $('input[name="checkbox12"]:checked').val()+ "\n";
	  result -= $('input[name="checkbox12"]:unchecked').val() + "\n";
	  
	  result += $('input[name="checkbox13"]:checked').val()+ "\n";
	  result -= $('input[name="checkbox13"]:unchecked').val() + "\n";
	  
	  result += $('input[name="checkbox14"]:checked').val()+ "\n";
	  result -= $('input[name="checkbox14"]:unchecked').val() + "\n";
	  
	  result += $('input[name="checkbox15"]:checked').val()+ "\n";
	  result -= $('input[name="checkbox15"]:unchecked').val() + "\n";
	  
	  result += $('input[name="checkbox16"]:checked').val()+ "\n";
	  result -= $('input[name="checkbox16"]:unchecked').val() + "\n";
	  
	 
	  [color="#2E8B57"]//get page LenteSelectieScherm2[/color]
	  result += "Accentkleuren: " + $('input[name="checkbox1"]:checked').val() + $('input[name="checkbox1"]:unchecked').val() + "\n";
result -= $('input[name="checkbox1"]:unchecked').val() + "\n";
	  
	  if("checkbox1" = 'checked'  
      result += $('input[name="checkbox2"]:checked').val()+ "\n";
	  result -= $('input[name="checkbox2"]:unchecked').val() + "\n";
	  
	  result += $('input[name="checkbox3"]:checked').val()+ "\n";
	  result -= $('input[name="checkbox3"]:unchecked').val() + "\n";
	  
	  result += $('input[name="checkbox4"]:checked').val()+ "\n";
	  result -= $('input[name="checkbox4"]:unchecked').val() + "\n";
	  
	  result += $('input[name="checkbox5"]:checked').val() + "\n";
	  result -= $('input[name="checkbox5"]:unchecked').val() + "\n";
	  
	  result += $('input[name="checkbox6"]:checked').val()+ "\n";
	  result -= $('input[name="checkbox6"]:unchecked').val() + "\n";
	  
	  result += $('input[name="checkbox7"]:checked').val()+ "\n";
	  result -= $('input[name="checkbox7"]:unchecked').val() + "\n";
	  
	  result += $('input[name="checkbox8"]:checked').val()+ "\n";
	  result -= $('input[name="checkbox8"]:unchecked').val() + "\n";
	  
	  result += $('input[name="checkbox9"]:checked').val()+ "\n";
	  result -= $('input[name="checkbox9"]:unchecked').val() + "\n";
	  
	  result += $('input[name="checkbox10"]:checked').val()+ "\n";
	  result -= $('input[name="checkbox10"]:unchecked').val() + "\n";
	  
	  result += $('input[name="checkbox11"]:checked').val()+ "\n";
	  result -= $('input[name="checkbox11"]:unchecked').val() + "\n";
	  
	  result += $('input[name="checkbox12"]:checked').val()+ "\n";
	  result -= $('input[name="checkbox12"]:unchecked').val() + "\n";
	  
	  result += $('input[name="checkbox13"]:checked').val()+ "\n";
	  result -= $('input[name="checkbox13"]:unchecked').val() + "\n";
	  
	  result += $('input[name="checkbox14"]:checked').val()+ "\n";
	  result -= $('input[name="checkbox14"]:unchecked').val() + "\n";
	  
	  result += $('input[name="checkbox15"]:checked').val()+ "\n";
	  result -= $('input[name="checkbox15"]:unchecked').val() + "\n";
	  
	  result += $('input[name="checkbox16"]:checked').val()+ "\n";
	  result -= $('input[name="checkbox16"]:unchecked').val() + "\n";
	
	  
	  [color="#2E8B57"]//schrijf tekst[/color]
	  result += "Uitgevoerd door Charlies Studio"
	  update summary page
	  $('[id$=summaryTextArea]').text(result);


This it the code for the 'submit form'

phoneui.postSubmitForm_m1_review_p3 = function(isSuccess, data) {
  // add custom postubmission processing code here,
  // e.g., parse and process results & update UI controls with data as needed
  // return false to terminate form processing
  var result = true;
  if (isSuccess) {
    // process data
    result = true;
  } else {
    // submit failed
    // data = error msg
    result = false;
  }
  return result;
}

Thanks for the help.

Vic

This post has been edited by andrewsw: 18 December 2013 - 03:51 AM
Reason for edit:: Use code tags


Is This A Good Question/Topic? 0
  • +

Replies To: Survey with multiple answers

#2 andrewsw   User is offline

  • no more Mr Potato Head
  • member icon

Reputation: 6957
  • View blog
  • Posts: 28,696
  • Joined: 12-December 12

Re: Survey with multiple answers

Posted 18 December 2013 - 03:49 AM

result -= $('input[name="checkbox1"]:unchecked').val() + "\n";

You cannot subtract from a string. I'm not sure what you expect this to do(?).
Was This Post Helpful? 0
  • +
  • -

#3 vicbelien   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 3
  • Joined: 18-December 13

Re: Survey with multiple answers

Posted 18 December 2013 - 03:58 AM

Yeah, i'm aware of that "-=". but if you place "+=" in front it still doesn't work. So the dummie inside me told me to try that.

If the checkbox is checked I want the value of that checkbox (a color name e.g. royal blue) to appear in the answer form.
If the checbox is unchecked I want no value and i don't want "Undefined" in the form.
Also I want to select multiple checkboxes per page. E.g. 6/16 on page 1 and 10/16 on page 2.
Was This Post Helpful? 0
  • +
  • -

#4 andrewsw   User is offline

  • no more Mr Potato Head
  • member icon

Reputation: 6957
  • View blog
  • Posts: 28,696
  • Joined: 12-December 12

Re: Survey with multiple answers

Posted 18 December 2013 - 04:36 AM

Moved to the jQuery forum.



The first few "+=" probably work, but as soon as it encounters "-=" an error occurs.

My impression is that you only want to reference the checkboxes that are checked.

$('input[name^="checkbox"]:checked')

should select all the inputs that begin with 'checkbox'. You'll probably need to loop through all of them to construct the string:

$('input[name^="checkbox"]:checked').each(..)

[If this doesn't create the string in the order that you want (checkbox1, checkbox2,..) then you would have to inspect each checkbox in order, using an if-statement to see if each one is checked.]

This post has been edited by andrewsw: 18 December 2013 - 04:36 AM

Was This Post Helpful? 0
  • +
  • -

#5 vicbelien   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 3
  • Joined: 18-December 13

Re: Survey with multiple answers

Posted 18 December 2013 - 11:05 AM

Thanks for your help, I'll try it out right away!
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1