Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Validation

Status
Not open for further replies.

mchoudhury

Programmer
Nov 26, 2004
71
GB
Hi Guys,
I have this drop down menu where u select a item then another drop down menu gets populated - chained list. This is writtten in vb.net. i'm trying to do the validation through vb.net but this intercepts with the second drop down, therefore the only other option of me doing this validation is through JavaScript.

I have very little knowledge of JS i was wondering i some one could help me on this:
I have a drop down list where the initial value is 0 (select a list) if a user dont select any item from the list and press the submit button then a alert box needs to pop up showing them to select an item from the list.

Form name- frmTelephoneSuppliers
Drop down name - ddlLineRentalSupplier - initial value 0 - please select a supplier.

Hope someone could help with this function for me.

Thanks
Mac
 
No code - no help. You gotta show us what you're working with, and the REAL code, not imaginary stuff.

Lee
 
This is my front end drop down coding in asp.net:
<p>
<td> Telephone line rental supplier?</td>
<td><asp:dropdownlist id="ddlLineRentalSupplier" datavaluefield="TelephoneSupplierID" datatextfield="TelephoneSupplierName" runat="server">
</asp:dropdownlist>

</td>
</p>

This is my back end codeing:

ddlLineRentalSupplier.Attributes("onChange") = "fillDdl(" & ddlCallPlan.ClientID & ", this.value);"

Private Function CreateJavaScript() As String
'
Dim li As ListItem
Dim sbOutputString As New System.Text.StringBuilder()
'
For Each li In ddlLineRentalSupplier.Items
'
If IsNumeric(li.Value) Then
If CInt(li.Value) > 0 Then
sbOutputString.Append(CreateCallPlanJavaScript(li.Value))
End If
End If
'
Next
'
For Each li In ddlSecondSupplier.Items
'
If IsNumeric(li.Value) Then
If CInt(li.Value) > 0 Then
sbOutputString.Append(CreateCallPlanJavaScript(li.Value))
End If
End If
'
Next
'
Return sbOutputString.ToString
'
End Function

how can i write a new function where validation will take place if no item is selcetd from the drop down list.

Thanks
 
Show the output to get help here. There's no Javascript in what you wrote.

Lee
 
In the Page_Load event (aspx.vb):
Code:
btnSubmit.Attributes.Add("onClick","return checkDDL();");
In your .aspx page:
Code:
<script Language="JavaScript">
function checkDDL()
{
if(Form1.ddlLineRentalSupplier.selectedIndex == 0)
	{
		alert("Please select a Supplier.");
		Form1.ddlLineRentalSupplier.focus();
		return false;
	}
}
</script>
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top