views:

443

answers:

1

I have a HTML fomr which uses special characters in ids ( :,-,_ ). The form uses JQuery validation plugin to validate the user input. Specifically the id includes a GUID Following is the sample code:

<script src="../../Scripts/jquery-1.3.2.js" type="text/javascript"></script>
    <script src="../../Scripts/jquery-validate/jquery.validate.js" type="text/javascript"></script>
    <script type="text/javascript">
        $(document).ready(function() {
            $('#respondForm').validate({ onclick: false,
                onkeyup: false,
                onfocusout: false,
                highlight:
function(element, errorClass) {
    $(element).css({ backgroundColor: '#FFFF88' });
}
,
                errorLabelContainer: $("ul", $('div.error-container')),
                wrapper: 'li',
                rules: { Input:_CDD66FA6-D190-434D-AF51-8272F64E0646_14ecbb3f-c0e0-4caf-b03a-013d12118405:
{
    required: true
, minlength: 5
, maxlength: 10
}

                }
,
                messages: { firstName:
{
    required: "xxx_Required"
, minlength: "XXX Should be greater than 5"
, maxlength: "XXX Cannot be greater than 10"
}

                }
            });
        });

    </script>
</head>
<body>
<form action="/Home/Submit" method="post" id="respondForm">  
   <div>
    <div class="error-container">
    <ul>

    </ul>
    </div>   
    </div>
    <div>    
        <input type="text" id="Input:_CDD66FA6-D190-434D-AF51-8272F64E0646_14ecbb3f-c0e0-4caf-b03a-013d12118405" name="Input:_CDD66FA6-D190-434D-AF51-8272F64E0646_14ecbb3f-c0e0-4caf-b03a-013d12118405" />        
        <br />
        <input type="submit" name="submit" value="Submit" />
        <br />

    </div>
</form>

As you can observe input type text element has the id/name as "Input:_CDD66FA6-D190-434D-AF51-8272F64E0646_14ecbb3f-c0e0-4caf-b03a-013d12118405"

If I run this page in the browser, I receive a JavaScript error:

Webpage error details

Message: Expected '}' Line: 23 Char: 50 Code: 0 URI: http://localhost:64603/

The error is pointing to this line:

function(element, errorClass) {
    $(element).css({ backgroundColor: '#FFFF88' });
}
,
                errorLabelContainer: $("ul", $('div.error-container')),
                wrapper: 'li',
***[Line 23] ----->   rules: { Input:_CDD66FA6-D190-434D-AF51-8272F64E0646_14ecbb3f-c0e0-4caf-b03a-013d12118405:***

How do I resolve this?

+1  A: 

"Crescent Fresh" your suggestion worked, wrapping the id in single quotes:

rules: { 'Input:_CDD66FA6-D190-434D-AF51-8272F64E0646_14ecbb3f-c0e0-4caf-b03a-013d12118405':
{

makes it work

Ngm
Good, I'm glad. The error message was a huge giveaway.
Crescent Fresh