I am currently having a html code as:
<form>
<input type="text" name="price1" size="14" value="Rs.900" readonly="readonly"/>
<input type="text" name="price2" size="14" value="Rs.600" readonly="readonly"/>
<input type="text" name="price3" size="14" value="Rs.500" readonly="readonly"/>
</form>
<form name="qty">
<input type="text" name="quant1" id="id1" size="14" value="0"/>
<input type="text" name="quant2" id="id2" size="14" value="0" />
<input type="text" name="quant3" id="id3" size="14" value="0" />
</form>
<input type="button" onclick="calculate()" value="Submit" />

On clicking the submit button i want the value entered in qty form gets multiplied by corresponding price & gets returned using a javascript function.
Also how to validate the qty form, so as to allow only numeric values.
Please respond.

Thanks in Advance

Recommended Answers

All 2 Replies

Member Avatar for stbuchok

Can you show the calculate function that you've wrote so far?

<html>
<head>
<style type="text/css">
.style1
{

width:500px;
background-color:#b0e0e6;
}
</style>
<script type ="text/javascript">
function validate(f11)
{
var a =f11.t2.value;
var b =f11.t3.value;
var c =/^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/;
var d =f11.t4.value;
var x = /^([A-Za-z0-9]){6,10}$/;
var y = f11.t5.value;
var passwd= /^([A-Za-z0-9_\-\.\@\)\(\+]){8,20}$/;
var phnoe = /^([0-9]){10,12}$/;
var phno = f11.tp.value;

if(document.f1.t1.value=='')
{
alert("please fill the field");
return false;
}

<!-- validation using regular expression so that phone no must be within 10 to 12 and contain numbers only-->

if(phnoe.test(phno)== false)
{
alert("please re enter valid phone no ");
return false;
}
<!-- validation using regular expression so that password must not contain some special charector only & should be within 8 to 20-->
if(passwd.test(b)== false)
{
alert("your password is not between 8 to 20 or containing unsupported charector");
return false;
}

if(a!=b)
{
alert("please re enter");
return false;
}
if(c.test(d)== false)
{
alert("please re enter valid email id ");
return false;
}
<!-- validation using regular expression so that username must not contain special charector & should be within 6 to 10-->
if(x.test(y)== false)
{
alert(" username must not contain special charector & should be within 6 to 10");
return false;
}

<!-- validation for dropdown list-->

if(document.f1.car.selectedIndex <=0)
{
alert("please select a car");

return false;
}

<!-- validation for radio button-->

var radioselected=false;
for(i=0; i<document.f1.gender.length; i++)
{
if(document.f1.gender.checked)
radioselected=true;
}
if(!radioselected)
{
alert("please select at least one gender value");

}

<!-- validation for checkbox -->
if (document.f1.c1.checked == false &&
document.f1.c2.checked == false &&
document.f1.c3.checked == false)
{
alert ('You didn\'t choose any of the checkboxes!');
return false;
}

}
</script>
</head>
<body bgcolor = "olive">
<center>
<div class ="style1" >

<form name ="f1" onsubmit = "return validate(this)">

<h1> form validation using javascript </h1>
name<input type ="text" name="t1" value=""/> <P>

phone no<input type ="text" name="tp" value=""/><P>
password:<input type ="password" name="t2" value=""/> <P>
re enter :<input type ="password" name="t3" value=""/> <P>
email ::<input type ="text" name="t4" value=""/> <P>

<!-- user name field-->
desired username: <input type ="text" name="t5" value=""/> <P>

<!--drop down list-->
car :<select name="car">
<option value="0" selected="selected">Select One</option>
<option value ="volvo">Volvo</option>
<option value="saab">Saab</option>
<option value= "bike">bike</option>
<option value ="santro">Santro</option>

</select> <p>
<!-- radio button field -->
select geder:<input type="radio" name="gender" value="female ">FEMALE
<input type="radio" name="gender" value="male ">MALE <p>

<!-- checkbox field -->
select course :
<input type="checkbox" name="c1" value="c++" />C++
<input type="checkbox" name="c2" value="java" />CORE JAVA
<input type="checkbox" name="c3" value="os" />OS <p>

<input type ="submit" value ="click">
</form>

</div>
</center>
</body>
</html>

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.