CodeCharge Studio
search Register Login  

Web Reports

Visually create Web Reports in PHP, ASP, .NET, Java, Perl and ColdFusion.
CodeCharge.com

YesSoftware Forums -> Archive -> GotoCode Archive

 Client on change validation

Print topic Send  topic

Author Message
Karen
Posted: 10/09/2003, 8:39 AM

I am trying to use the client side validation in the 'On Change' event of a control. However, I keep getting javascript error which says that 'document.control.value' is null or not an object. What am I doing wrong? I'm using CCS/PHP/MySQL. Pls help!

TIA!
Karen
Posted: 10/09/2003, 8:50 AM

I should add that I'm trying to do this in an editable grid. Perhaps that could be a problem. Anyone knows?
Karen
Posted: 10/10/2003, 1:17 AM

Actually, after thinking abt it, I think my question should be how to reference the particular field in the editable grid since just selecting the control name is not sufficient becoz there are several rows of the same control. Can any javascript/CCS guru offer some suggestions?

TIA!
RonB
Posted: 10/10/2003, 11:44 PM

Hi Karen,

You can ad onchange code easely in html. Go to the field in the editable grid table you want the code to go and add sommething like this:

onchange='document.all.{parent_id_Name}.value=1'

here's the resulting html for an editable grid I tried this on(it works):

<!-- BEGIN EditableGrid rb_html -->
<form name="{HTMLFormName}" action="{Action}" method="post">
Lijst van Rb Html{Label1} <input type="hidden" value="{FormState}" name="FormState">{FormScript}
<table>
<!-- BEGIN Error -->
<tr>
<td colspan="6">{Error}</td>
</tr>
<!-- END Error -->
<tr>
<td>Art Id </td>
<td>Parent Id </td>
<td>Art Title </td>
<td>Art Html </td>
<td>Art Order </td>
<td>Verwijder </td>
</tr>

<!-- BEGIN Row -->
<!-- BEGIN RowError -->
<tr>
<td colspan="6">{Error}</td>
</tr>
<!-- END RowError -->
<tr>
<td>{art_id} </td>
<td><input maxlength="10" size="10" value="{parent_id}" name="{parent_id_Name}" onchange='document.all.{parent_id_Name}.value=1'> </td>
<td><input maxlength="150" size="50" value="{art_title}" name="{art_title_Name}"> </td>
<td><textarea name="{art_html_Name}" rows="3" cols="50">{art_html}</textarea> </td>
<td><input maxlength="10" size="10" value="{art_order}" name="{art_order_Name}"> </td>
<td>
<!-- BEGIN CheckBox CheckBox_Delete --><input type="checkbox" value="1" name="{CheckBox_Delete_Name}" {CheckBox_Delete}><!-- END CheckBox CheckBox_Delete --> </td>
</tr>
<!-- END Row -->
<!-- BEGIN NoRecords -->
<tr>
<td colspan="6">Geen gegevens  </td>
</tr>
<!-- END NoRecords -->
<tr>
<td align="right" colspan="6">
<!-- BEGIN Navigator Navigator -->
<!-- BEGIN Prev_On --><a href="{Prev_URL}"><img src="Themes/Default/PrevOn.gif" border="0"></a> <!-- END Prev_On -->
<!-- BEGIN Prev_Off --><img src="Themes/Default/PrevOff.gif" border="0"><!-- END Prev_Off -->
<!-- BEGIN Next_On --><a href="{Next_URL}"><img src="Themes/Default/NextOn.gif" border="0"></a> <!-- END Next_On -->
<!-- BEGIN Next_Off --><img src="Themes/Default/NextOff.gif" border="0"><!-- END Next_Off --><!-- END Navigator Navigator --> 
<!-- BEGIN Button Button_Submit --><input type="submit" value="Verzend" name="{Button_Name}"><!-- END Button Button_Submit -->  </td>
</tr>

</table>
</form>
<!-- END EditableGrid rb_html -->



Hope this helps,

Ron
Karen
Posted: 10/11/2003, 12:16 AM

Hi Ron,

Thank you very much, Ron, I think I know what you mean. I should go into the HTML and code the javascript right next to the control. Would you kindly help me a little more with the javascript?

I would like to test the value entered is within a certain range, and if not valid, have a pop-up message (alert) and then put the cursor back in that same field so the user must change the value.

I added the action validation to the on change event of the control and it generated code that looked something like this. This appeared right at the top of the HTML code. I'm not sure how to adapt this.

Really appreciate the help!

------------------
<script language="JavaScript">
//Begin CCS script
//Include JSFunctions @1-DA3E7A20
</script>
<script language="JavaScript" src="functions.js"></script>
<script language="JavaScript">

//End Include JSFunctions

//page_sessionlines_order_qty_OnChange @8-1B1E295D
function page_sessionlines_order_qty_OnChange()
{
var result;
//End page_sessionlines_order_qty_OnChange

//Validate Minimum Value @45-EACE9D75
if(document.order_qty.value < 1) {
alert("test")
document.order_qty.focus();
return false;
}
//End Validate Minimum Value

//Close page_sessionlines_order_qty_OnChange @8-BC33A33A
return result;
}
//End Close page_sessionlines_order_qty_OnChange

//bind_events @1-1461F052
function bind_events() {
if(typeof(initsessionlinesElements) == "function"){
initsessionlinesElements();
for(var i = 0; i < sessionlinesElements.length; i++){
sessionlinesElements[sessionlinesorder_qtyID].onchange = page_sessionlines_order_qty_OnChange;
}
}
forms_onload();
}
//End bind_events

window.onload = bind_events; //Assign bind_events @1-19F7B649

//End CCS script
</script>
RonB
Posted: 10/11/2003, 3:16 AM

Haven't tried it but you could define the two functions as seperate functions in the head section and adapt it slightly:

function page_sessionlines_order_qty_OnChange(fieldname)
{
var result;
//End page_sessionlines_order_qty_OnChange

//Validate Minimum Value @45-EACE9D75
if(document.fieldname.value < 1) {
alert("test")
document.fieldname.focus();
return false;
}
//End Validate Minimum Value

//Close page_sessionlines_order_qty_OnChange @8-BC33A33A
return result;
}
now call this function in the grids html as explained in my previous posting but remember to ad the field_Name in the function call:

onchange='page_sessionlines_order_qty_OnChange({order_qty_Name})'


the fieldname in the functiondeclaration will now be substituted for the controll's name for that row.

Hope this helps

Ron
Karen
Posted: 10/12/2003, 8:22 PM

Hi Ron,

I got it to work by replacing in the generated code, document.order_qty with the array element. Thanks for your tips, it really helped me to understand the generated code.

-Karen

   


These are Community Forums for users to exchange information.
If you would like to obtain technical product help please visit http://support.yessoftware.com.

Web Database

Join thousands of Web developers who build Web applications with minimal coding.
CodeCharge.com

Home   |    Search   |    Members   |    Register   |    Login


Powered by UltraApps Forum created with CodeCharge Studio
Copyright © 2003-2004 by UltraApps.com  and YesSoftware, Inc.