I've borrowed some code from two different sources and splice them together. One works (The ordering total) but the 2nd one (Minimum order) does not. I'm a newb when it comes to Java and probably am just missing a command or something.
'total' is being used for both and should be re enabling the submit button once 'total' is above 20.
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>temp</title>
<script language="javascript">
function calculate(form)
{
var item1 = form.item1.value;
var item2 = form.item2.value;
form.total.value = (item1 * 10) + (item2 * 30);
};
</script>
<script language="javascript">
setInterval(function () {
if ($('#total').val() >= 20)
$(":submit").removeAttr("disabled");
else
$(":submit").attr("disabled", "disabled");
}, 1);
</script>
</head>
<body>
<form method="POST" action="<?php echo htmlspecialchars($_SERVER['PHP_SELF']); ?>" >
<table border="1" cellspacing="1" width="757">
<tr>
<td width="224" align="center"><strong>Quantity</strong></td>
<td width="39" align="center"><strong>price</strong></td>
<td width="476" align="center"><strong>total</strong></td>
</tr>
<tr>
<td width="224">item1<input type="number" name="item1" size="20" onchange="calculate(this.form)" value="0"></td>
<td width="39">$10</td>
</tr>
<tr>
<td width="224">item2<input type="number" name="item2" size="20" onchange="calculate(this.form)" value="0"> </td>
<td width="39">$30</td>
</tr>
<tr>
<td width="224"> </td>
<td width="39">total</td>
<td width="476"> <input type="number" name="total" size="20"></td>
</tr>
</table>
<p><input type="submit" value="Submit Order" disabled title="Order is below $20 minimum."></p>
</form>
</body>
</html>
$('#total') looks for element with id total, but you don't have it (you have only name),
so, by adding id - form is working
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>temp</title>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script language="javascript">
function calculate(form)
{
var item1 = form.item1.value;
var item2 = form.item2.value;
form.total.value = (item1 * 10) + (item2 * 30);
};
</script>
<script language="javascript">
setInterval(function () {
if ($('#total').val() >= 20)
$(":submit").removeAttr("disabled");
else
$(":submit").attr("disabled", "disabled");
}, 1);
</script>
</head>
<body>
<form method="POST" action="<?php echo htmlspecialchars($_SERVER['PHP_SELF']); ?>" >
<table>
<tr>
<td align="center"><strong>Quantity</strong></td>
<td align="center"><strong>price</strong></td>
<td align="center"><strong>total</strong></td>
</tr>
<tr>
<td>item1<input type="number" name="item1" size="20" onchange="calculate(this.form)" value="0"></td>
<td width="39">$10</td>
</tr>
<tr>
<td>item2<input type="number" name="item2" size="20" onchange="calculate(this.form)" value="0"> </td>
<td>$30</td>
</tr>
<tr>
<td> </td>
<td>total</td>
<td> <input type="number" id="total" name="total" size="20"></td>
</tr>
</table>
<p><input type="submit" value="Submit Order" disabled title="Order is below $20 minimum."></p>
</form>
</body>
</html>
Related
Trying to create a Javascript for future value calculation. This is the code im using but it is not returning a value. Don't know where the code is wrong. Has user input investment, interest rate, monthly payment added, and terms. After that code how do I create a for loop to create an amortization schedule.
<body>
<form name="fv">
<table>
<tr><td colspan="3"><b>Enter Investment Information:</b></td></tr>
<tr>
<td>1)</td>
<td>Amount of the Investment (any currency):</td>
<td>
<input type="text" name="investment" size="12"
onchange="calculate();">
</td>
</tr>
<tr>
<td>2)</td>
<td>percentage rate of interest:</td>
<td>
<input type="text" name="interest" size="12"
onchange="calculate();">
</td>
</tr>
<tr>
<td>3)</td>
<td>Monthly Payment Amount:</td>
<td>
<input type="text" name="monthly" size="12"
onchange="calculate();">
</td>
</tr>
<tr>
<td>4)</td>
<td>Terms:</td>
<td>
<input type="text" name="terms" size="12"
onchange="calculate();">
</td>
</tr>
<tr>
<td colspan="3">
<input type="button" value="Calculate" onclick="calculate();">
</td>
</tr>
<tr>
<td colspan="3">
<b>Investment Information:</b>
</td>
</tr>
<tr>
<td>4)</td>
<td>Your Investment will be worth:</td>
<td><input type="text" name="payment" size="12"></td>
</tr>
</table>
</form>
<script language="JavaScript">function calculate() {
var investment = document.fv.investment.value;
var interest = document.fv.interest.value / 100 / 12;
var terms = document.fv.terms.value * 12;
var x = Math.pow(1 + interest, terms);
var monthly = (investment * x);
if (!isNaN(monthly) &&
(monthly != Number.POSITIVE_INFINITY) &&
(monthly != Number.NEGATIVE_INFINITY)) {
document.fv.payment.value = round(monthly);
}
else {
document.fv.payment.value = "";
}
}
function round(x) {
return Math.round(x * 100) / 100;
</script>
I don't know what exactly you meant but it return value into input you haven't closed round func and wrong type on script
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
</head>
<body>
<form name="fv">
<table>
<tr><td colspan="3"><b>Enter Investment Information:</b></td></tr>
<tr>
<td>1)</td>
<td>Amount of the Investment (any currency):</td>
<td>
<input type="text" name="investment" size="12"
onchange="calculate();">
</td>
</tr>
<tr>
<td>2)</td>
<td>percentage rate of interest:</td>
<td>
<input type="text" name="interest" size="12"
onchange="calculate();">
</td>
</tr>
<tr>
<td>3)</td>
<td>Monthly Payment Amount:</td>
<td>
<input type="text" name="monthly" size="12"
onchange="calculate();">
</td>
</tr>
<tr>
<td>4)</td>
<td>Terms:</td>
<td>
<input type="text" name="terms" size="12"
onchange="calculate();">
</td>
</tr>
<tr>
<td colspan="3">
<input type="button" value="Calculate" onclick="calculate();">
</td>
</tr>
<tr>
<td colspan="3">
<b>Investment Information:</b>
</td>
</tr>
<tr>
<td>4)</td>
<td>Your Investment will be worth:</td>
<td><input type="text" name="payment" size="12"></td>
</tr>
</table>
</form>
<script type="text/javascript">
function calculate() {
var investment = document.fv.investment.value;
var interest = document.fv.interest.value / 100 / 12;
var terms = document.fv.terms.value * 12;
var x = Math.pow(1 + interest, terms);
var monthly = (investment * x);
if (!isNaN(monthly) && (monthly !== Number.POSITIVE_INFINITY) &&
(monthly !== Number.NEGATIVE_INFINITY)) {
document.fv.payment.value = round(monthly);
}
else {
document.fv.payment.value = "";
}
}
function round(x) {
return Math.round(x * 100) / 100;
}
</script>
</body>
</html>
i have form it display value in same page after click submit button,it's all work fine
but i need to get grand total value when i click the submit button every time.
please can any one help me
here is my full code.
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/jqueryui/1.11.4/jquery-ui.min.js"></script>
<link rel="stylesheet" href="custom.css" type="text/css">
<html lang="en">
<head>
<meta charset="utf-8">
<title>Add Sales</title>
<script type="text/javascript">
$(document).ready(function() {
$("#stk").change(function(){
document.getElementById('total').value=document.getElementById('pric').value * document.getElementById('stk').value;
});
});
function add_values(){
if(document.getElementById('edit_guid').value==""){
if( document.getElementById('stk').value!="" && document.getElementById('total').value!="" ){
if(document.getElementById('stk').value!=0){
sell=document.getElementById('pric').value;
disc=document.getElementById('stk').value;
total=document.getElementById('total').value;
item=document.getElementById('guid').value;
roll=parseInt(document.getElementById('roll_no').value);
$('<tr id='+item+'><td><lable id='+item+'roll >'+roll+'</label></td><td><input type=text readonly="readonly" value='+sell+'></td><td><input type=text readonly="readonly" value='+disc+' ></td><td><input type=text readonly="readonly" value='+total+'> </td></tr>').fadeIn("slow").appendTo('#item_copy_final');
document.getElementById('stk').value="";
document.getElementById('pric').value="";
document.getElementById('roll_no').value=roll+1;
document.getElementById('total').value="";
document.getElementById('guid').value="";
}
}else{
alert('Please Select An Item');
}
}
}
</script>
<body>
<form name="form1" method="post" id="form1" action="">
<input type="hidden" id="roll_no" value="1" >
<div align="center">
<input type="hidden" id="guid">
<input type="hidden" id="edit_guid">
<table class="form" >
<tr>
<td>price</td>
<td></td>
<td>stk</td>
<td>totall</td>
</tr>
<tr>
<td>
<td><input type='text' class='form-control' id="pric" name="pric"></td>
<td><input type='text' class='form-control' id="stk" name="stk"></td>
<td><input type='text' class='form-control' id="total" name="total1"></td>
<td><input type="button" onclick="add_values()" id="add_new_code" value="submit" class="round"></div></form></td></tr>
</table>
<div style="overflow:auto ;max-height:300px; ">
<table class="form" id="item_copy_final" style="margin-left:45px ">
</table>
</div>
</div>
<div class="mytable_row ">
<form>
<div align="center">
<table>
<td>grand totall</td>
<td><input type="text" id="grand_tot" name="grand_tot"></td>
</table>
</div>
</form>
</body>
</html>
Finally i got the answer this may help to some one.
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/jqueryui/1.11.4/jquery-ui.min.js"></script>
<link rel="stylesheet" href="custom.css" type="text/css">
<html lang="en">
<head>
<meta charset="utf-8">
<title>Add Sales</title>
<script type="text/javascript">
$(document).ready(function() {
//$("#stk").change(function(){
//document.getElementById('total').value=document.getElementById('pric').value * document.getElementById('stk').value;
//});
$("#pric,#stk").keyup(function () {
$('#total').val($('#pric').val() * $('#stk').val());
});
});
function add_values(){
if(document.getElementById('edit_guid').value==""){
if( document.getElementById('stk').value!="" && document.getElementById('total').value!="" ){
if(document.getElementById('stk').value!=0){
sell=document.getElementById('pric').value;
disc=document.getElementById('stk').value;
total=document.getElementById('total').value;
item=document.getElementById('guid').value;
//item=document.getElementById('guid').value;
roll=parseInt(document.getElementById('roll_no').value);
$('<tr id='+item+'><td><lable id='+item+'roll >'+roll+'</label></td><td><input type=text readonly="readonly" value='+sell+'></td><td><input type=text readonly="readonly" value='+disc+' ></td><td><input type=text readonly="readonly" class="submited-total" value='+total+'> </td></tr>').fadeIn("slow").appendTo('#item_copy_final');
document.getElementById('stk').value="";
document.getElementById('pric').value="";
document.getElementById('roll_no').value=roll+1;
document.getElementById('total').value="";
//document.getElementById('roll_no').value="";
document.getElementById('guid').value="";
submitedTotal = 0;
$('.submited-total').each(function(){
submitedTotal = this.value;
});
if(document.getElementById('grand_tot').value==""){
document.getElementById('grand_tot').value=submitedTotal;
}else{
submitedTotal =parseFloat(document.getElementById('grand_tot').value)+ parseFloat(submitedTotal);
}
$('#grand_tot').val(submitedTotal);
}
}else{
alert('Please Select An Item');
}
}
}
</script>
<body>
<form name="form1" method="post" id="form1" action="">
<input type="hidden" id="roll_no" value="1" >
<div align="center">
<input type="hidden" id="guid">
<input type="hidden" id="edit_guid">
<table class="form" >
<tr>
<td>price</td>
<td></td>
<td>stk</td>
<td>totall</td>
</tr>
<tr>
<td>
<td><input type='text' class='form-control' id="pric" name="pric"></td>
<td><input type='text' class='form-control' id="stk" name="stk"></td>
<td><input type='text' class='form-control' id="total" name="total1"></td>
<td><input type="button" onclick="add_values()" id="add_new_code" value="submit" class="round"></div></form></td></tr>
</table>
<div style="overflow:auto ;max-height:300px; ">
<table class="form" id="item_copy_final" style="margin-left:45px ">
</table>
</div>
</div>
<div class="mytable_row ">
<form>
<div align="center">
<table>
<td>grand totall</td>
<td><input type="text" id="grand_tot" name="grand_tot"></td>
</table>
</div>
</form>
</body>
</html>
I try But , Its Take The Current Text Value In GrandTotal and Overright it ....
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/jqueryui/1.11.4/jquery-ui.min.js"></script>
<link rel="stylesheet" href="custom.css" type="text/css">
<html lang="en">
<head>
<meta charset="utf-8">
<title>Add Sales</title>
<script type="text/javascript">
$(document).ready(function() {
$("#stk").change(function(){
document.getElementById('total').value=document.getElementById('pric').value * document.getElementById('stk').value;
});
});
function add_values(){
if(document.getElementById('edit_guid').value==""){
if( document.getElementById('stk').value!="" && document.getElementById('total').value!="" ){
if(document.getElementById('stk').value!=0){
var current_TOTAL = document.getElementById('total').value=document.getElementById('pric').value * document.getElementById('stk').value;
var sell=document.getElementById('pric').value;
var disc=document.getElementById('stk').value;
var total=document.getElementById('total').value;
var item=document.getElementById('guid').value;
var grand_total =document.getElementById('grand_tot').value;
var full_total = 0;
full_total = 0;
var full_total = document.getElementById('total').value;
roll=parseInt(document.getElementById('roll_no').value);
$('<tr id='+item+'><td><lable id='+item+'roll >'+roll+'</label></td><td><input type=text readonly="readonly" value='+sell+'></td><td><input type=text readonly="readonly" value='+disc+' ></td><td><input type=text readonly="readonly" value='+total+'> </td></tr>').fadeIn("slow").appendTo('#item_copy_final');
document.getElementById('stk').value="";
document.getElementById('pric').value="";
document.getElementById('roll_no').value=roll+1;
document.getElementById('total').value="";
document.getElementById('guid').value="";
document.getElementById('grand_tot').value=full_total;
}
}else{
alert('Please Select An Item');
}
}
}
</script>
<body>
<form name="form1" method="post" id="form1" action="">
<input type="hidden" id="roll_no" value="1" >
<div align="center">
<input type="hidden" id="guid">
<input type="hidden" id="edit_guid">
<table class="form" >
<tr>
<td>price</td>
<td></td>
<td>stk</td>
<td>totall</td>
</tr>
<tr>
<td>
<td><input type='text' class='form-control' id="pric" name="pric"></td>
<td><input type='text' class='form-control' id="stk" name="stk"></td>
<td><input type='text' class='form-control' id="total" name="total1"></td>
<td><input type="button" onclick="add_values()" id="add_new_code" value="submit" class="round"></div></form></td></tr>
</table>
<div style="overflow:auto ;max-height:300px; ">
<table class="form" id="item_copy_final" style="margin-left:45px ">
</table>
</div>
</div>
<div class="mytable_row ">
<form>
<div align="center">
<table>
<td>grand totall</td>
<td><input type="text" id="grand_tot" name="grand_tot"></td>
</table>
</div>
</form>
</body>
</html>
I am using jQuery for creating multiple text fields on button click. It is working fine. Now I need to validate all test boxes.
This is my HTML code:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Patient Portal</title>
<!--[if IE]>
<link rel="stylesheet" type="text/css" href="css/style2.css" />
<![endif]-->
<!--[if !IE]> -->
<link rel="stylesheet" type="text/css" href="css/style.css" />
<!-- <![endif]-->
<script type="text/javascript" language="javascript" src="js/scripts.js"></script>
<script type="text/javascript" language="javascript" src="js/basicnifo.js"></script>
<script src="js/jquery-1.3.2.min.js"></script>
<script src="js/jquery.validate.js"></script>
<script type="text/javascript" src="js/datepicker2.js"></script>
</head>
<body>
<table width="100%" border="0" align="center" cellpadding="0" cellspacing="0" class="m5">
<tr>
<td valign="top" class="m4">
<form action="#" method="post" name="reg" id="reg">
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td><div class="m12">
<table width="100%" border="0" cellspacing="1" cellpadding="2" id="items">
<thead>
<tr>
<td colspan="7" align="center" bgcolor="#62a3e0" style="width:15%;"><strong>Problem List</strong></td>
</tr>
<tr>
<td align="center" bgcolor="#EAEAEA" style="width:1%;"><strong>Problem</strong></td>
<td align="center" bgcolor="#EAEAEA" style="width:1%;"><strong>Status</strong></td>
<td align="center" bgcolor="#EAEAEA" style="width:1%;"><strong>Active Date</strong></td>
</tr>
</thead>
<tbody>
<tr>
<td bgcolor="#F5F5F5" style="width:15%;"><input type="text" tabindex="1" name="Problem1" id="Problem1" class="m16 autocomplete" value="" /></td>
<td bgcolor="#F5F5F5" style="width:15%;"><select name="Status1" id="Status1" class="drop2" tabindex="1" >
<option value="1" selected="selected">active</option>
<option value="2">in-active</option>
</select></td>
<td bgcolor="#F5F5F5" style="width:15%;"><input type="text" name="Date1" id="Date1" class="m16 datepick" tabindex="1" value=""/></td>
<input type="hidden" name="patientProblemsid1" id="patientProblemsid1" class="m16" value="0"/>
<input type="hidden" name="sSaved" id="sSaved" value="null" class="m10" />
</tr>
</tbody>
<tfoot>
<tr>
<td colspan="5" align="right">
<input type="button" name="update" id="update" value="ADD ROW" tabindex="10" class="bt-press add_more" onmouseover="changeBgImage('images/button-bg2.png', 'update')" onmouseout="changeBgImage('images/button-bg.png', 'update')" /></td>
</tr>
<tr>
<td colspan="5" align="right">
<input type="submit" name="button" id="SAVE" value="SAVE" class="bt-press" tabindex="50" onmouseover="changeBgImage('images/button-bg2.png', 'SAVE')" onmouseout="changeBgImage('images/button-bg.png', 'SAVE')" />
<input type="submit" name="button" id="NEXT" value="NEXT" class="bt-press" tabindex="51" onmouseover="changeBgImage('images/button-bg2.png', 'NEXT')" onmouseout="changeBgImage('images/button-bg.png', 'NEXT')" /></td>
</tr>
</tfoot>
<input type="hidden" name="item_count" id="item_count" value="1" />
<input type="hidden" name="page" value="patienthistory" class="m10" />
<input type="hidden" name="Cliinicid" value="" class="m10" />
</table>
</div></td>
</tr>
</table>
</form>
<div class="m7"> <br />
</div>
</td>
</tr>
</table>
</body>
</html>
And this is my JavaScript part for adding text boxes on button click:
<script>
$(".add_more").click(function(event){
event.preventDefault();
var count = $("#item_count").val();
count = parseInt(count);
//alert(count);
var new_count = count +1;
// alert(new_count);
// $(".delete_link").remove();
var html = '<tr>\
<td bgcolor="#F5F5F5" style="width:15%;"><input type="text" name="Problem'+new_count+'" id="Problem'+new_count+'" tabindex="11" class="m16 autocomplete" value="" /></td> \
<td width="15%" bgcolor="#F5F5F5" style="width:15%;"><select name="Status'+new_count+'"id="Status'+new_count+'" tabindex="11" class="drop2 ">\
<option value="1" selected="selected"> active</option><option value="2">inactive</option>\
</select></td> \
<td bgcolor="#F5F5F5" style="width:15%;"><input type="text" name="Date'+new_count+'" id="Date'+new_count+'" tabindex="11" class="m16 datepicker" value="" /></td> \
</tr>';
var $html = $(html);
var $ht = $html.find('input.datepicker')[0];
$($ht).datepicker({dateFormat:"mm-dd-yy"});
$('#items > tbody:last').append($html);
$("#item_count").val(new_count);
});
</script>
I need to validate all text boxes. Thanks in advance.
.validate() Will help you to validate your form elements with use of ID or class of a form.
You please follow the following URL to get validation for your script:
http://jqueryvalidation.org/validate/
In your validation script validate each input type text field using same class name like.
$("#SAVE").click(function(){ $(".m16").each(function(){
var values=this.value;
if(values.length<1)
{
alert("Text box empty");
}
});
});
I've a table named 'pedidos' and a table named 'locais'. For each 'pedidos' there can be several 'locais'. So I'm using this form
In the right column I want the user to type the data for each 'locais' which includes an image file. Then when the user clicks on 'Acrescentar Local' the table on the left is being filled. But instead off adding the image as well it loses the file.
I'm using the code:
<link rel="stylesheet" type="text/css" media="screen" href= "redmond/jquery-ui-1.10.3.custom.css" />
<link rel="stylesheet" type="text/css" media="screen" href="ui.jqgrid.css" />
<script type="text/javascript" src="jquery-1.9.0.min.js"></script>
<script src="grid.locale-en.js" type="text/javascript"></script>
<script src="jquery.jqGrid.src.js" type="text/javascript"></script>
<title>Untitled Document</title>
</head>
<body>
<script language="javascript">
var a=0;
var clone = [];
function addLoc()
{
/* var tmp = jQuery('#foto').clone();
clone.push(tmp[0]);*/
/*document.getElementById('loc_table').innerHTML+="<tr><td>"+document.getElementById('local').value+"</td><td>"+document.getElementById('comp').value+"</td><td>"+document.getElementById('larg').value+"</td><td>"+clone[a]+"</td></tr>";*/
document.getElementById('loc_table').innerHTML+="<tr><td>"+document.getElementById('local').value+"</td><td>"+document.getElementById('comp').value+"</td><td>"+document.getElementById('larg').value+"</td><td><input type='file' id='foto"+a+"'/></td></tr>";
document.getElementById('foto'+a)=document.getElementById('foto');
a++;
/*
"+document.getElementById('foto').value+"</td></tr>";
*/
}
</script>
<table>
<tr>
<td>
<form id='addPed' name='addPed' action='#' method='POST'>
<table>
<tr>
<td><label for="nome">nome</label></td>
<td><input type="text" id="nome" /></td></tr><tr>
<td><label for="desc">descricao</label></td>
<td><input type="text" id="desc" /></td></tr><tr>
<td><label for="datai">data de insercao</label></td>
<td><input type="text" id="datai" /></td></tr><tr>
<td><label for="datae">data de entrega</label></td>
<td><input type="text" id="date" /></td></tr><tr>
<td></td>
<td><input type="button" value="Adicionar pedido"/></td></tr>
</table>
<br/>
LOCAIS:
<br/>
<br/>
<table id="loc_table">
<tr>
<td class="tableheader">local</td>
<td class="tableheader">comprimento</td>
<td class="tableheader">largura</td>
<td class="tableheader">foto</td>
</tr>
</table>
<!-- </form> -->
</td>
<td>
<!-- <form id='addLoc' name='addPed' action='#' method='POST'> -->
<table>
<tr>
<td><label for="local">local</label></td>
<td><input type="text" id="local" /></td></tr><tr>
<td><label for="comp">comprimento</label></td>
<td><input type="text" id="comp" /></td></tr><tr>
<td><label for="larg">largura</label></td>
<td><input type="text" id="larg" /></td></tr><tr>
<td><label for="foto">foto</label></td>
<td><input type="file" id="foto" /></td></tr><tr>
<td></td>
<td><input type="button" value="Acrescentar Local" onclick="addLoc()"/></td></tr>
</table>
</form>
</td>
</tr>
</table>
Can Anyone sugest me a solution please!
Thanks
i'm having the below jsp page created.
<%#page contentType="text/html" pageEncoding="UTF-8"%>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>JSP Page</title>
<script type="text/javascript">
function show(x)
{
document.getElementById(x).style.display='block';
}
function hide(x)
{
document.getElementById(x).style.display='none';
}
function handleKeyEvent(e) {
var charCode;
if (e && e.which) {
charCode = e.which;
} else if (window.event) {
e = window.event;
charCode = e.keyCode;
}
if (charCode == 13) {
//document.getElementById("yourForm").submit();
var m=document.getElementById(e);
alert(m);
hide(x);
}
}
</script>
</head>
<body>
<form name="form1" method="post" action="abc.jsp">
<table width="722">
<tr>
<td width="431" height="190">
<table width="439" >
<tr>
<td width="129">PARTS Updated</td>
<td width="108"><p>
<select name="PARTS_Updated" id="PARTS_Updated" >
<option value=""></option>
<option value="N/A">N/A</option>
</select>
</p></td>
<td width="186"><label for="PARTS_Updated"></label></td>
</tr>
<tr>
<td>TSI OK
</td>
<td><p>
<input type="radio" name="radio" id="TSI_N/A" value="TSI_N/A" onClick="hide('TSI_Query_Box')">
N/A
</p>
<p>
<input type="radio" name="radio" id="TSI_Query" value="TSI_Query" onClick="show('TSI_Query_Box')"> TSI Query</p></td>
<td><label for="TSI_Query_Box"></label>
<textarea name="TSI_Query_Box" id="TSI_Query_Box" cols="15" rows="5" style="display:none" onkeypress="handleKeyEvent('TSI_Query_Box')"></textarea></td>
</tr>
<tr>
<td height="65">Special Ins OK
</td>
<td><p>
<input type="radio" name="radio" id="SI_N/A" value="TSI_OK" onClick="hide('SI_Query_Box')">
N/A
</p>
<p>
<input type="radio" name="radio" id="SI_Query" value="SI_Query" onClick="show('SI_Query_Box')"> SI Query</p></td>
<td><label for="SI_Query_Box"></label>
<textarea name="SI_Query_Box" id="SI_Query_Box" cols="15" rows="5" style="display:none" onkeypress="handleKeyEvent('SI_Query_Box')"></textarea></td>
</tr>
</table></td>
<td width="279">
<table width="279" align="center">
<tr>
<td width="87"><p>Shipment ID
</p></td>
<td width="97"><label for="Ship_ID"></label>
<input type="text" name="Ship_ID" id="Ship_ID"></td>
</tr>
</table></td>
</tr>
</table>
<p> </p>
<table width="721" border="1">
<tr>
<td width="374" align="center">
<input type="submit" name="Send for CT Review (SCTR)" id="Send for CT Review (SCTR)" value="Send for CT Review (SCTR)"></td>
<td width="331" align="center">
<input type="submit" name="CT Review Complete (CTRC" id="CT Review Complete (CTRC)" value="CT Review Complete (CTRC)"></td>
</tr>
<tr>
<td align="center">
<input type="submit" name="Cleanup Queries" id="Cleanup Queries" value="Cleanup Queries"></td>
<td align="center">
<input type="submit" name="Cleanup Complete" id="Cleanup Complete" value="Cleanup Complete"></td>
</tr>
<tr>
<td colspan="2" align="center"><input type="submit" name="Go_To_Main_Page" id="Go_To_Main_Page" value="Go To Main Page"></td>
</tr>
</table>
<p> </p>
</form>
<h1> </h1>
</body>
</html>
i wanted to see when i enter the text in textarea and hit enter, i want to see the text assed. in the present case it is alerting a message [object]. Also when i check radio buttons, if i check TSI Query Radio button followed SI Query Radio button or vice versa, both are getting displayed, i want only one textarea to be displayed once.
for screenshot you can have a look at this link
http://jsfiddle.net/dYy26/
Thanks.
Check this code:
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>JSP Page</title>
<script type="text/javascript">
function show(x,y)
{
document.getElementById(x).style.display='block';
document.getElementById(y).style.display='none';
document.getElementById('Ship_IDl').style.display='block';
}
function hide(x,y)
{
document.getElementById(x).style.display='none';
document.getElementById(y).style.display='block';
document.getElementById('Ship_IDl').style.display='none';
}
function handleKeyEvent(e) {
var charCode;
if (e && e.which) {
charCode = e.which;
} else if (window.event) {
e = window.event;
charCode = e.keyCode;
}
if (charCode == 13) {
//document.getElementById("yourForm").submit();
var m=document.getElementById(e);
alert(m);
hide(x);
}
}
</script>
</head>
<body>
<form name="form1" method="post" action="abc.jsp">
<table width="722">
<tr>
<td width="431" height="190">
<table width="439" >
<tr>
<td width="129">PARTS Updated</td>
<td width="108"><p>
<select name="PARTS_Updated" id="PARTS_Updated" >
<option value=""></option>
<option value="N/A">N/A</option>
</select>
</p></td>
<td width="186"><label for="PARTS_Updated"></label></td>
</tr>
<tr>
<td>TSI OK
</td>
<td><p>
<input type="radio" name="radio" id="TSI_N/A" value="TSI_N/A" onClick="hide('TSI_Query_Box','SI_Query_Box')">
N/A
</p>
<p>
<input type="radio" name="radio" id="TSI_Query" value="TSI_Query" onClick="show('TSI_Query_Box','SI_Query_Box')"> TSI Query</p></td>
<td><label for="TSI_Query_Box"></label>
<textarea name="TSI_Query_Box" id="TSI_Query_Box" cols="15" rows="5" style="display:none" onkeypress="handleKeyEvent('TSI_Query_Box')"></textarea></td>
</tr>
<tr>
<td height="65">Special Ins OK
</td>
<td><p>
<input type="radio" name="radio" id="SI_N/A" value="TSI_OK" onClick="hide('SI_Query_Box','TSI_Query_Box')">
N/A
</p>
<p>
<input type="radio" name="radio" id="SI_Query" value="SI_Query" onClick="show('SI_Query_Box','TSI_Query_Box')"> SI Query</p></td>
<td><label for="SI_Query_Box"></label>
<textarea name="SI_Query_Box" id="SI_Query_Box" cols="15" rows="5" style="display:none" onkeypress="handleKeyEvent('SI_Query_Box')"></textarea></td>
</tr>
</table></td>
<td width="279">
<table width="279" align="center">
<tr>
<td width="87"><p>Shipment ID
</p></td>
<td width="97"><label for="Ship_ID"></label>
<input type="text" name="Ship_ID" id="Ship_ID"></td>
</tr>
</table></td>
</tr>
</table>
<p> </p>
<table width="721" border="1">
<tr>
<td width="374" align="center">
<input type="submit" name="Send for CT Review (SCTR)" id="Send for CT Review (SCTR)" value="Send for CT Review (SCTR)"></td>
<td width="331" align="center">
<input type="submit" name="CT Review Complete (CTRC" id="CT Review Complete (CTRC)" value="CT Review Complete (CTRC)"></td>
</tr>
<tr>
<td align="center">
<input type="submit" name="Cleanup Queries" id="Cleanup Queries" value="Cleanup Queries"></td>
<td align="center">
<input type="submit" name="Cleanup Complete" id="Cleanup Complete" value="Cleanup Complete"></td>
</tr>
<tr>
<td colspan="2" align="center"><input type="submit" name="Go_To_Main_Page" id="Go_To_Main_Page" value="Go To Main Page"></td>
</tr>
</table>
<p> </p>
</form>
<h1> </h1>
</body>
</html>
Check this:
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>JSP Page</title>
<script type="text/javascript">
function show(x,y)
{
document.getElementById(x).style.display='block';
document.getElementById(y).style.display='none';
document.getElementById('Ship_IDl').style.display='block';
}
function hide(x,y)
{
document.getElementById(x).style.display='none';
document.getElementById(y).style.display='block';
document.getElementById('Ship_IDl').style.display='none';
}
function myKeyPress(e,x,y){
var keynum;
if(window.event){ // IE
keynum = e.keyCode;
}else
if(e.which){ // Netscape/Firefox/Opera
keynum = e.which;
}
//alert(String.fromCharCode(keynum));
//alert(keynum);
if (keynum == 13) {
//document.getElementById("yourForm").submit();
var m=document.getElementById(x).value;
alert(m);
hide(x,y);
}
}
</script>
</head>
<body>
<form name="form1" method="post" action="abc.jsp">
<table width="722">
<tr>
<td width="431" height="190">
<table width="439" >
<tr>
<td width="129">PARTS Updated</td>
<td width="108"><p>
<select name="PARTS_Updated" id="PARTS_Updated" >
<option value=""></option>
<option value="N/A">N/A</option>
</select>
</p></td>
<td width="186"><label for="PARTS_Updated"></label></td>
</tr>
<tr>
<td>TSI OK
</td>
<td><p>
<input type="radio" name="radio" id="TSI_N/A" value="TSI_N/A" onClick="hide('TSI_Query_Box','SI_Query_Box')">
N/A
</p>
<p>
<input type="radio" name="radio" id="TSI_Query" value="TSI_Query" onClick="show('TSI_Query_Box','SI_Query_Box')"> TSI Query</p></td>
<td><label for="TSI_Query_Box"></label>
<textarea name="TSI_Query_Box" id="TSI_Query_Box" cols="15" rows="5" style="display:none" onkeypress="return myKeyPress(event,'TSI_Query_Box','SI_Query_Box')"></textarea></td>
</tr>
<tr>
<td height="65">Special Ins OK
</td>
<td><p>
<input type="radio" name="radio" id="SI_N/A" value="TSI_OK" onClick="hide('SI_Query_Box','TSI_Query_Box')">
N/A
</p>
<p>
<input type="radio" name="radio" id="SI_Query" value="SI_Query" onClick="show('SI_Query_Box','TSI_Query_Box')"> SI Query</p></td>
<td><label for="SI_Query_Box"></label>
<textarea name="SI_Query_Box" id="SI_Query_Box" cols="15" rows="5" style="display:none" onkeypress="return myKeyPress(event,'SI_Query_Box','TSI_Query_Box')""></textarea></td>
</tr>
</table></td>
<td width="279">
<table width="279" align="center">
<tr>
<td width="87"><p>Shipment ID
</p></td>
<td width="97"><label for="Ship_ID" id="Ship_IDl"></label>
<input type="text" name="Ship_ID" id="Ship_ID"></td>
</tr>
</table></td>
</tr>
</table>
<p> </p>
<table width="721" border="1">
<tr>
<td width="374" align="center">
<input type="submit" name="Send for CT Review (SCTR)" id="Send for CT Review (SCTR)" value="Send for CT Review (SCTR)"></td>
<td width="331" align="center">
<input type="submit" name="CT Review Complete (CTRC" id="CT Review Complete (CTRC)" value="CT Review Complete (CTRC)"></td>
</tr>
<tr>
<td align="center">
<input type="submit" name="Cleanup Queries" id="Cleanup Queries" value="Cleanup Queries"></td>
<td align="center">
<input type="submit" name="Cleanup Complete" id="Cleanup Complete" value="Cleanup Complete"></td>
</tr>
<tr>
<td colspan="2" align="center"><input type="submit" name="Go_To_Main_Page" id="Go_To_Main_Page" value="Go To Main Page"></td>
</tr>
</table>
<p> </p>
</form>
<h1> </h1>
</body>
</html>