How to check blank radio button in form?

Want to make sure all the question have answer

Page 1 of 1

4 Replies - 14061 Views - Last Post: 04 March 2008 - 11:26 PM

#1 jilong  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 33
  • Joined: 17-May 07

How to check blank radio button in form?

Posted 29 February 2008 - 02:54 AM

In my question form i would like to split it into 3 step/pages.

When user finish first page question and click the next button the form will hide the first pages question and second page question will display.

But before they process to the next page i would like to check all the question have been answer.

Below is one of my question. I use the for loop to check for the radio button if it is not selected the alert message will pop up.

My problem is if the question 1 is not selected there will have 5 time pop up message. Even after i select one of the answer for question 1 there will still pop up the alert message for 4 time then only continue to next page.

Is there have any ideal for me to have only 1 time pop up for the alert message?

Select your language.<br />
<input name="question1_1" type="radio" value="English" /> English 
<input name="question1_1" type="radio" value="Japanese"/> Japanese 
<input name="question1_1" type="radio" value="French"/> French 
<input name="question1_1" type="radio" value="German"/> German 
<input name="question1_1" type="radio" value="Chinese"/> Chinese<br />
<input type="button" style="width:100px" value="Next" onclick="pages2(this.form);">




function pages2(pages2){
var $check = '';

for(i=0; i<3; i++){
if(pages2.question1_1[i].checked == false) {
 alert("Please select your language.");
 $check = 'Wrong'
}
}

if($check != 'Wrong'){
document.getElementById('pages3').style.display = '';
document.getElementById('pages2').style.display = 'none';
} 
}



This post has been edited by jilong: 29 February 2008 - 03:09 AM


Is This A Good Question/Topic? 0
  • +

Replies To: How to check blank radio button in form?

#2 no2pencil  Icon User is online

  • Admiral Fancy Pants
  • member icon

Reputation: 5396
  • View blog
  • Posts: 27,390
  • Joined: 10-May 07

Re: How to check blank radio button in form?

Posted 29 February 2008 - 03:01 AM

You want to find the question1_1 that has a value of checked

http://www.w3schools...s/tag_input.asp
http://www.w3schools...e=tryhtml_radio
Was This Post Helpful? 0
  • +
  • -

#3 jilong  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 33
  • Joined: 17-May 07

Re: How to check blank radio button in form?

Posted 29 February 2008 - 03:16 AM

View Postno2pencil, on 29 Feb, 2008 - 03:01 AM, said:

You want to find the question1_1 that has a value of checked

http://www.w3schools...s/tag_input.asp
http://www.w3schools...e=tryhtml_radio



Yes, my form is a questionnaire. so there have no radio-button is checked before user click on it.

In my function i call "pages2.question1_1[i].checked == false", if false mean all radio-button are unchecked and the alert message pop up.

actually my problem is other than for loop what looping can i use for this?
Was This Post Helpful? 0
  • +
  • -

#4 no2pencil  Icon User is online

  • Admiral Fancy Pants
  • member icon

Reputation: 5396
  • View blog
  • Posts: 27,390
  • Joined: 10-May 07

Re: How to check blank radio button in form?

Posted 29 February 2008 - 03:38 AM

View Postjilong, on 29 Feb, 2008 - 03:16 AM, said:

actually my problem is other than for loop what looping can i use for this?

Is for not working? Why would you want to use anything else? You could use do-while or do-until.
Was This Post Helpful? 0
  • +
  • -

#5 jilong  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 33
  • Joined: 17-May 07

Re: How to check blank radio button in form?

Posted 04 March 2008 - 11:26 PM

View Postno2pencil, on 29 Feb, 2008 - 03:38 AM, said:

View Postjilong, on 29 Feb, 2008 - 03:16 AM, said:

actually my problem is other than for loop what looping can i use for this?

Is for not working? Why would you want to use anything else? You could use do-while or do-until.


The "for" is working, but if the radio button have 5 answer to select, the alert message will pup up for 5 time. Event if i already one anser the alert message will still pop another 4 time.

After i decide to not use loop and just write out all the array and it work nice.

if(pages2.question1_1[0].checked == false && pages2.question1_1[1].checked == false && pages2.question1_1[2].checked == false && pages2.question1_1[3].checked == false ) {

alert("Please select your language.");

}


Was This Post Helpful? 0
  • +
  • -

Page 1 of 1