Hi to all
i have done validation on single fields but i have to apply validation on 3 text field that at least one of thre is filled .i make a code but that logic doesnot work ..

html code

<html>
<head>
<script type="text/javascript" src="jstest.js"></script>
</head>
<img src="idtech_logo.jpg" alt="logo" width="1500" height="80" />

<body bgcolor="#1E90FF">

<form method="POST"
        onsubmit="return validate_form(this)" action="insert.php">
<h1>
<font size="15" face="Monotype Corsiva" color="black">
<center>ID Technologies</center></font></h1>

<form>
<center>
<table>

<tr>
     <td width="50%"> First Name: </td> 
     <td> <input type="text" name="fname" /> </td>
</tr>
<tr>
      <td width="50%"> Last Name :</td> 
      <td> <input type="text" name="lname" /></td>
</tr>
<tr>

      <td width="50%"> Organization Name:</td>
      <td> <input type="text" name="oname"/></td>
</tr>
<tr>

        <td width="50%">Email:</td> 
        <td><input type="text" name="email" /></td>
</tr>

<tr>

   <td width="50%">Contact Number:</td>
   <td><input type="text" name="cno" /></td>
</tr>

<tr>
<td width="50%">Duration in years:</td>
<td><input type="text" name="years"/ ></td>

</tr>
</table>
</center>
<br/>
<center>
<table>
<input type="radio"/>Extend<br/>
<input type="radio"/>Read Only<br/><br/>

</center>
</table>

<center>
<table>

<a href="WindowsFormsApplication6.exe">Download link</a>
</br></br>

<tr>

   <td width="50%">MAC ID:</td>
   <td><input id="input1" type="text" name="mid" /></td>
</tr>

<tr>

   <td width="50%">CPU ID:</td>
   <td><input id="input2" type="text" name="cid"/></td>
</tr>

<tr>

   <td width="50%">MotherBoard ID:</td>
   <td><input id="input3" type="text" name=""mbid/></td>
</tr>

</table>
</center>
</br></br>
<center>
<input type="submit" value="submit"/>
</center>
</form>


</body>
</html>

js code

function validate_required(field,alerttxt) {
	with (field) {
		if (value==null||value=="") {
			alert(alerttxt);
			return false;
		}
		else {
			return true;
		}
	}
}

function validate_email(field,alerttxt) {
	with (field) {
		apos=value.indexOf("@")
		dotpos=value.lastIndexOf(".")
		if (apos<1||dotpos-apos<2) {
			alert(alerttxt);
			return false;
		} else {
			return true;
		}
	}
}

[B]function check_one_select(){
var input1 = document.getElementById('input1');
var input2 = document.getElementById('input2');
var input3 = document.getElementById('input3');
if(input1.value == '' &  input2.value == ''& input3.value == ''){
alert("enter value in atleast one ");
return false;
}
else{
return true;}
[/B]
}



function validate_form(thisform) {
	with (thisform) {
		if (validate_required(fname,"Please specify your First Name!")==false) {
			fname.focus();
			return false;
		}
		if (validate_required(email,"Email must be filled out!")==false) {
			email.focus();
			return false;
		}
		if (validate_email(email,"Not a valid e-mail address!")==false) {
			email.focus();
			return false;
		}
		if (validate_required(oname,"Specify the organization name!")==false) {
			oname.focus();
			return false;
		}
                if (validate_required(cno,"Enter your contact number!")==false) {
			cno.focus();
			return false;
		}

               [B]if (check_one_select()==false) {
			mid.focus();
			return false;
		}[/B]
	}
}

the remaining code execute except the bold one...the problem is in the check_one_select().can u please help me to solve this problem

Recommended Answers

All 3 Replies

Check line 81:

<td width="50%">MotherBoard ID:</td>
<td><input id="input3" type="text" name=""mbid/></td>
="text" name=""mbid/>

should be

="text" name="mbid" />

I don't know Jquery or JS really, but I'd put a bet on that quote being the problem.

That's the first thing I noticed as well...

<input id="input3" type="text" name=""mbid/></td>
//needs to be fixed 
//name="mbid";
// I ran the code it all seems to function just fine as long as the mbid is fixed.

thanks to all of u.it worked...

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.