javascript – using the data in form in a function-ThrowExceptions

Exception or error:

So basically I want to take the data in the form and use it in a function.

HTML:

<form id="form1" onsubmit="Ordering()">
		
				<input id="X" type="checkbox">
				<input id="Y" type="checkbox">
			
			<input type="submit" value="order">
			<input type="reset">
			
	
		
		</form>

Java Script:

function Ordering()
{
	alert("Hello! I am an alert box!!");
	
	if(document.getElementById('X')==true;)
	{
		action='whatsapp://send?abid=&text=';
	}
	if(document.getElementById('Y')==true;)
	{
	action='ailto:pizza@manheten.co.il?subject=Pizza%20order&body=123';
}

but i cant activate the script at all… i tried to use an alert to see if its even getting there … but with no success .. any suggestions?

How to solve:

There are some typos and you need to use value to get the value and compare as follows:

function Ordering() {
  alert('hello');
  if (document.getElementById('X').value) {
    action = 'whatsapp://send?abid=&text=';
  }
  if (document.getElementById('Y').value) {
    action = 'ailto:pizza@manheten.co.il?subject=Pizza%20order&body=123';
  }
}
<form id="form1" onsubmit="Ordering()">
  <input id="X" type="checkbox">
  <input id="Y" type="checkbox">
  <input type="submit" value="order">
  <input type="reset">
</form>

Leave a Reply

Your email address will not be published. Required fields are marked *