Click to See Complete Forum and Search --> : Click button/submit validate field and open a window
shanuragu
06-11-2003, 07:43 AM
HI
I have two text boxes in a form and a Go button/ submit (not sure) . When I click the button it should validate the text fields & then open a window using window.open(). Iam able to open the window but cannot validate fields. if I use submit button it just gives the alert msg & opens the window.
Please help.
ShaRa
Post the code you are using.
shanuragu
06-11-2003, 08:18 AM
Here is the code
<script language="javascript">
function ShowPrintDetails()
{
var no1,no2,mode;
no1=document.form.ord_no1.value;
no2=document.form.ord_no2.value;
window.open("OrderStatusReport.asp?ordno1="+escape(no1) + "&ordno2="+escape(no2),"","left=100,top=100,width=500, height=500,status=no,toolbar=no,menubar=no,location=no,resizable=yes,scrollbars=yes")
}
// validation is done for one field only - testing purpose
function Validate()
{
if (document.form.ord_no1.value="")
{
alert("cannot leave blank Enter Value...");
document.form.ord_no1.focus();
return false;
}
}
</script>
//HTML part
<tr>
<td width="35%" align="right">
<b>Print Order Status List:</b>
</td>
<td align="left" width="35%">
OrderNo
From: BG-
<input type="text" name='ord_no1' tabindex='1' size="6" ">
</td>
<td width="25%">TO: BG-
<input type="text" name='ord_no2' size="6" tabindex='2' ;
<input type="button" name="Go" value="Go" class='button8' onclick="document.form.mode.value='Go'; Validate(); ShowPrintDetails();">
</td>
<td width="25%" align="left"> </td>
</tr>
ShaRa
vickers_bits
06-11-2003, 08:24 AM
im not exactly sure about what it is that ur trying to do...but it could just be that u forgot to use return Validate()
DaiWelsh
06-11-2003, 08:57 AM
I am guessing you want the ShowPrintDetails call to be dependent on the Validation? Probably the best bet would be to break out a new function to call. e.g.
function blah()
{
document.form.mode.value='Go';
if(Validate())
{
ShowPrintDetails();
return true;
}
else
{ return false; }
}
<input type="button" name="Go" value="Go" class='button8' onclick="return blah();">
You could do this all in the onclick handler but it would be harder to read. Also you should make sure your Validate function returns true or false by adding a return true at the end if all the checks are passed.
If you still want the form to submit afterwards (I doubt it from your description) then just change it back to a submit button and it will submit if the validation was passed and not otherwise.
HTH,
Dai