Welcome Guest, Not a member yet? Register   Sign In
validate multi select list box in javascript?
#1

[eluser]Zeeshan Rasool[/eluser]
Cany any one tell me how can we validate listbox in javascript
I have a list containing categories and i need to make it required for the user but i cant get the result in JS. I put the server side validation in Controller but also i need it in JS Please help.

Thanks !
#2

[eluser]Phil Sturgeon[/eluser]
Are you lucky enough to be using jQuery or are you using native JavaScript or some other library?

What sort of validation are you trying to achieve? What should the value be? Should it have a certain pattern?

Please provide us with enough to actually answer you. "Can you tell me how to code?" is not a very good start to a thread.
#3

[eluser]Zeeshan Rasool[/eluser]
[quote author="Phil Sturgeon" date="1260549071"]Are you lucky enough to be using jQuery or are you using native JavaScript or some other library?
[/quote]

Smile Actually i am not using jquery for validation recently its native Javascript.
My Code is simply
Code:
<select name='store_category_id[]' multiple="multiple">
<option value='1' >Dresses</option>
<option value='2' >Dresses&nbsp;>&nbsp;Skirts</option>
<option value='3' >Shirts</option>                            
</select>

i need to validate if user doesn't select any category ?
#4

[eluser]Phil Sturgeon[/eluser]
You're lucky, I'm bored. ;-)

Code:
<scr1pt type="text/javascript">
            
             window.onload = function()
             {
                 document.getElementById('some-random-form').onsubmit = function()
                {
                     if(document.getElementById('store_category_id').value == '')
                     {
                        alert('FAAAAAAAIIIIIIIIIIIL!');
                        return false;
                    }
                }
            }
         </scr1pt>
        
         &lt;form id="some-random-form"&gt;
            <select name="store_category_id[]" id="store_category_id" multiple="multiple">
                <option value='1' >Dresses</option>
                <option value='2' >Dresses&nbsp;>&nbsp;Skirts</option>
                <option value='3' >Shirts</option>                            
            </select>
            
            &lt;input type="submit" /&gt;
        &lt;/form&gt;
#5

[eluser]Zeeshan Rasool[/eluser]
Thanks ! Phil Sturgeon, its really helpful. ;-)




Theme © iAndrew 2016 - Forum software by © MyBB