pink1 Posted November 4, 2007 Share Posted November 4, 2007 How to Repare this cod if i CHOOSE 2 radio button to worked.<script>function processSize(){ // Demonstrates radio buttons var size; var size1 var i; var theOption; for (i = 0; i <= 3; i++){ theOption = document.myForm.radSize1; theOption = document.myForm.radSize1; if (theOption.checked == true){ size = theOption.value; size1 = theOption.value; } // end if } // end for loop document.myForm.txtOutput.value = "OK, I'll get you the "; document.myForm.txtOutput.value += size+size1; } // end Link to comment Share on other sites More sharing options...
justsomeguy Posted November 5, 2007 Share Posted November 5, 2007 What does the form look like that has the radio buttons in it? You can't choose two radio buttons from the same group, so if you want to choose two buttons they will need to be in different groups. Link to comment Share on other sites More sharing options...
pink1 Posted November 6, 2007 Author Share Posted November 6, 2007 again don't word....... Help plz..!<script>function processSize(){ // Demonstrates radio buttons var size; var i; var theOption; for (i = 0; i <= 1; i++){ theOption = document.myForm.radSize; if (theOption.checked == true){ size += theOption.value; } // end if } // end for loop document.myForm.txtOutput.value = "OK, I'll get you the "; document.myForm.txtOutput.value += size + " one.";} // end //--------------------------------------------------------------------------------------var size1; var i; var theOption; for (i = 0; i <= 1; i++){ theOption = document.myForm.radSize1; if (theOption.checked == true){ size1 = theOption.value; } // end if } // end for loop document.myForm.txtOutput.value = "OK, I'll get you the "; document.myForm.txtOutput.value += size1 + " one.";} // end </script> Link to comment Share on other sites More sharing options...
justsomeguy Posted November 6, 2007 Share Posted November 6, 2007 What does the form look like that has the radio buttons in it?That means the HTML form, not more Javascript. Link to comment Share on other sites More sharing options...
pink1 Posted November 6, 2007 Author Share Posted November 6, 2007 This cod here but again don't work.!>!>! [Help plz for the last time..!]<html><head><title>Size Chooser</title><script>function processSize(){// Demonstrates radio buttonsvar size;var i;var theOption;for (i = 0; i <= 1; i++){theOption = document.myForm.radSize;if (theOption.checked == true){size += theOption.value;} // end if} // end for loopdocument.myForm.txtOutput.value = "OK, I'll get you the ";document.myForm.txtOutput.value += size + " one.";} // end//--------------------------------------------------------------------------------------var size1;var i;var theOption;for (i = 0; i <= 1; i++){theOption = document.myForm.radSize1;if (theOption.checked == true){size1 = theOption.value;} // end if} // end for loopdocument.myForm.txtOutput.value = "OK, I'll get you the ";document.myForm.txtOutput.value += size1 + " one.";} // end</script></head><body><center><h1>Size Chooser<hr></h1><form name = myForm><h3>Which size would you like?</h3><table border = 5><tr> <td> <input type = "radio" name = radSize1 value = "small">Small </td> <td> <input type = "radio" name = radSize1 value = "medium">Medium </td></tr><tr> <td> <input type = "radio" name = radSize value = "large">Large </td> <td> <input type = "radio" name = radSize value = "jumbo">Jumbo </td></tr><tr> <td colspan = 2> <center> <input type = "button" value = "OK" onClick = "processSize()"> </center> </td></tr></table><textarea name = "txtOutput" rows = 5 cols = 40></textarea></form></center><hr></body></html> Link to comment Share on other sites More sharing options...
justsomeguy Posted November 6, 2007 Share Posted November 6, 2007 This cod here but again don't work.!>!>! [Help plz for the last time..!]Yes, I realize that it doesn't work, you've now posted 3 times saying that. I'm just trying to get you to post the code that is necessary to find out *why* it doesn't work. Is English your native language?You have this Javascript on top:<script>function processSize(){// Demonstrates radio buttonsvar size;var i;var theOption;for (i = 0; i <= 1; i++){theOption = document.myForm.radSize[i];if (theOption.checked == true){size += theOption.value;} // end if} // end for loopdocument.myForm.txtOutput.value = "OK, I'll get you the ";document.myForm.txtOutput.value += size + " one.";} // end//--------------------------------------------------------------------------------------var size1;var i;var theOption;for (i = 0; i <= 1; i++){theOption = document.myForm.radSize1[i];if (theOption.checked == true){size1 = theOption.value;} // end if} // end for loopdocument.myForm.txtOutput.value = "OK, I'll get you the ";document.myForm.txtOutput.value += size1 + " one.";} // end</script> First, you need a language attribute on the script tag, the value should be "text/javascript". You have a function there called processSize. When I format the code it looks like this: function processSize(){ // Demonstrates radio buttons var size; var i; var theOption; for (i = 0; i <= 1; i++){ theOption = document.myForm.radSize[i]; if (theOption.checked == true){ size += theOption.value; } // end if } // end for loop document.myForm.txtOutput.value = "OK, I'll get you the "; document.myForm.txtOutput.value += size + " one.";} // end//--------------------------------------------------------------------------------------var size1;var i;var theOption;for (i = 0; i <= 1; i++){theOption = document.myForm.radSize1[i];if (theOption.checked == true){size1 = theOption.value;} // end if} // end for loopdocument.myForm.txtOutput.value = "OK, I'll get you the ";document.myForm.txtOutput.value += size1 + " one.";} // end Now you can see that the processSize function ends right before the //----------------- line, that is the end of the function. The code after that is not part of the processSize function. By the time the browser gets down to the last } it sees that as a syntax error because there is no matching {, and so the function never gets defined and run when you click on the button.You need to include the second part of code inside the function block. You also don't need to redeclare i and theOption in the second part, they were already declared in the first part. Link to comment Share on other sites More sharing options...
Jesdisciple Posted November 6, 2007 Share Posted November 6, 2007 EDIT: Woops, simultaneous post. Link to comment Share on other sites More sharing options...
pink1 Posted November 6, 2007 Author Share Posted November 6, 2007 EDIT: Woops, simultaneous post.thnx for all help but this code dont work in my pc bye Link to comment Share on other sites More sharing options...
justsomeguy Posted November 6, 2007 Share Posted November 6, 2007 Haha, no kidding. It doesn't work in mine either, that's 'cause it's broken. I told you how to fix it. Good luck. Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.