Jump to content

No't woking code :(!


pink1
 Share

Recommended Posts

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

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

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

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

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...