What is wrong with this javascript?

mbeylis

Senior Member
Joined
Jun 8, 2006
Messages
564
Reaction score
2
Location
Benoni
Hi,

Below is the code, when I run it in IE the submit button does nothing? thanks, copy it into Notepad and rename as html and open in IE to try yourself :->

<html>
<head>
<title>Purchase Order</title>
</head>
<script language="javascript">
<!--hide from incompatible browsers

function recordPaymentMethod(paymentMethod, value){
if(paymentMethod=="Visa")
document.paymentMethod.selection1.value==paymentMethod;
else if(paymentMethod=="MasterCard")
document.paymentMethod.selection2.value==paymentMethod;
else if(payentMethod=="AmericanExpress")
document.paymentMethod.sleection2.value==paymentMethod;
}

function submit() {
if(document.paymentMethod.selection1.value==""||docuemnt.paymentMethod.selection2.value==""||document.paymentMethod.selection3.value==""){
alert("Please&nbsp;select&nbsp;payment&nbsp;method");
return false
}
}
//stop hiding from incompatible browsers-->
</script>
</head>

<body>
<form name=paymentMethod onclick=return recordPaymentMethod();">

<p>Payment Method? &nbsp;
<input type="radio" name="selection1" value="Visa"(1,this.value)";>Visa&nbsp;
<input type="radio" name="selection2" value="MasterCard"(1,this.value)";>Master Card&nbsp;
<input type="radio" name="selection3" value="AmericanExpress"(1,this.value)";>American Express&nbsp;
</p>

<p>
<form name="submit" onClick return="submit();">
<input type="button" name="Submit Order" value="Submit Order"();>
</p>

</body>
</html>
 
Its JAVA
:D

EDIT: I am assuming it does not change the selected option in the drop down as required?

Its because you need something like "Selected=true" or Option Selected or whatever it is.
I canna remnember now, but Value simply sets the Value, not the selected item.
 
Almost everything is wrong with the script and html. A lot of syntax errors.

Here's a working version:
Code:
<html>
<head>
<title>Purchase Order</title>
</head>
<script language="javascript">
<!--hide from incompatible browsers
function getRadioButtonValue(obj)
{
  for (var i = 0; i < obj.length; i++)
    if (obj[i].checked)
      return obj[i].value;
  return null;
}

function validate()
{
  var paymentMethod = getRadioButtonValue(document.paymentMethod);
  if (!paymentMethod)
  {
    alert("Please select payment method.");
    return false;
  }
  alert("You chose " + paymentMethod + "\r\nThe form is submitting.");
  return true;
}
//stop hiding from incompatible browsers-->
</script>
</head>

<body>
<form name="paymentMethod" method="post" onSubmit="return validate();">

<p>Payment Method? &nbsp;
<input type="radio" name="paymentMethod" value="Visa"/>Visa&nbsp;
<input type="radio" name="paymentMethod" value="MasterCard"/>Master Card&nbsp;
<input type="radio" name="paymentMethod" value="AmericanExpress"/>American Express
</p>

<p>
<input type="submit" value="Submit Order"/>
</p>
</form>

</body>
</html>
 
dude... I tried fixing this but fark me :eek:, there are about 9 spelling mistakes, weird brackets in wierd places, no closing tags for half the stuff (e.g. </form> and <input type="button" name="Submit Order" value="Submit Order"(); />)

I'd love to help, but clean your code and markup up before even trying to troubleshoot issues. Just because html/javascript isn't strict doesn't mean you may write messy code/markup.
 
PHP:
document.paymentMethod.selection1.value==paymentMe thod;

is also wrong, needs to be "="
 
Top
Sign up to the MyBroadband newsletter
X