PDA

View Full Version : What's wrong in my validation of SelectBox



Dorababu
Mar 09, 2012, 1:29 PM
I have written the following script to check whether selected index of Select Box is -1 or not but this is not working for me can any one help me.


<script type="text/javascript">
var onBeforeSubmit = function (select) {
if (select.value==-1) {
Ext.Msg.alert("Error", "Select an item.");
return false;
}
};
</script>

This is my button design


<ext:Button ID="Button1" runat="server" Text="Submit">
<DirectEvents>
<Click OnEvent="Select" Before="return onBeforeSubmit(#{SelectBox1})" />
</DirectEvents>
</ext:Button>

Daniil
Mar 10, 2012, 5:11 PM
Hi,

Well, the SelectBox value doesn't consist an index of a selected item.

I can suggest the getValue method, it returns null if there is no selected item.

Example

#{SelectBox1}.getValue() === null

Dorababu
Mar 12, 2012, 4:40 PM
You mean like this


<script type="text/javascript">
var onBeforeSubmit = function () {
if (#{SelectBox1}.getValue() === null) {
Ext.Msg.alert("Error", "Select an item.");
return false;
}
};
</script>

But still I am unable to display the alert

Daniil
Mar 12, 2012, 4:44 PM
Did you wrap that <script> in <ext:XScript> control? To get #{} syntax working.

Dorababu
Mar 12, 2012, 4:46 PM
Can you give me the code please I am not that much familiar with these tools and scripts

Daniil
Mar 12, 2012, 4:48 PM
Well, your initial code should work, just replace

if (select.value==-1) {
with

if (select.getValue() === null) {

Dorababu
Mar 12, 2012, 4:51 PM
Thanks Danill...