Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: Oracle VB.NET
I have created a table at runtime it has textbox control inside the table generated through for loop from 1 to 7 depending on dropdownlistselected value.
If the textbox controls value is empty i shuldnt allow the user to save data and need to focus the user into the text which is empty.
 
table has 3 columns
1 number
2 label
3 color picker
 
label is a textbox if any textbox is empty that is any row below label is empty do not allow user to save the data and set focus to the textbox where the feild is empty??how can i achieve this?
 

********* Runtime created table *********
Protected Sub ddlst_Scale_pointers_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles ddlst_Scale_pointers.SelectedIndexChanged
 
       Dim sb As New StringBuilder()
 
       sb.Append("<table id="table1" width="400" class="second" border="1px">")
       sb.Append("<tr>")
       sb.Append("<td>Pointer No</td>")
       sb.Append("<td>Pointer Label</td>")
       sb.Append("<td>Pointer Color</td>")
       sb.Append("</tr>")
       For i As Integer = 1 To ddlst_Scale_pointers.SelectedItem.Value
           sb.Append("<tr>")
           sb.Append("<td>" & i & "</td>")
           sb.Append("<td><input id='txtlbl" & i & "'  type='text' /></td>")
           sb.Append("<td><input id='txtcolour" & i & "' class='color' type='text' /></td>")
           sb.Append("</tr> ")
       Next
       sb.Append("</table>")
       sb.Append("")
       mydiv.InnerHtml = sb.ToString()
 
       For i As Integer = 1 To ddlst_Scale_pointers.SelectedItem.Value
       Next
     End Sub
 

Dim j As Integer
Dim name = Request.Form("nmlbl")
Dim col = Request.Form("nmcol")
Dim nameArr As String()
Dim colArr As String()

nameArr = split(name ,"")
colArr = split(col,"")

 
For j = 1 To ddlst_Scale_pointers.SelectedValue
If nameArr(j)="" and colArr(j)="" Then
MSgbox( "Please enter name & color for pointer" )
 
Else
MSgbox( "record saved" )
End If
 
Next
 

************ SAVING THE DATA INtO DATABASE *****************
 
If intEditID = 0 Then ' The Save Function should do an insert.
            If Not oPageAccessPermissions.getInsertPermission Then
                _retval.setErrorID(7)
                Return _retval
            Else ' add row for insert
                ' Step 4.INSERT MODE
                _retval = oMgr.trnkriScale_Insert_row(0, _
                                                        txtScaleName.Text, _
                                                        ddlstScale_Type.SelectedValue, _
                                                        ddlstScale_Measure.SelectedValue, _
                                                        txtDescription.Text, _
                                                         txtCode.Text, _
                                                        intLoggedInUserID)
 
               _retavl = oMgr.trnscalepointer_insert_row(0, nameArr(j) ,colArr(j) , "" ,"" , "" ,intLoggedInUserID)
 

 
            End If
 

<script language="javascript" type="text/javascript">
 
//function text_reason()
// {
// var tbl=document.getElementById('myTable');//ID of table which you have given.
// var txtpt = document.getElementById('txtpointer0').value;
// if(txtpt == null)
// {
// document.getElementById('txtpointer0').Focus;
// }
//
// var txtcl = document.getElementById ('txtcolour0').value;
// if (txtcl == null)
// {
// document.getElementById('txtcolour0').Focus;
// }
// }

//Below script i want to register
function text_reason()
{
alert("scr");

var vlue =document.getElementById('ddlst_Scale_pointers').value ;
//var myvalue ="Textmin" + 1;

for( i=1;i<=vlue;i++)
{
alert(i);
alert("Label VAL :" + document.getElementById('txtpointer').value);
var empt =document.getElementById('txtpointer').value;
alert("Color VAL :" + document.getElementById('txtcolour').value);
var empt1 =document.getElementById('txtcolour').value;

if( empt=="" or empt1="")
{
document.getElementById('txtpointer').focus();
document.getElementById('txtcolour').focus();
return false;

}
// myvalue ="Textmin" + (i+1);
// alert(myvalue );
}

}
</script>
 

How can i register this script?????
Posted 22-Feb-13 20:55pm
Edited 24-Feb-13 22:06pm
v2

1 solution

Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

Try this
 
1. add a asp:RequiredFieldValidator
2. The asp:RequiredFieldValidator has a property SetFocusOnError set it true.
SetFocusOnError="true"
 
Happy coding..
  Permalink  

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



Advertise | Privacy | Mobile
Web03 | 2.8.141022.2 | Last Updated 25 Feb 2013
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100