quick javascript help

Status
Not open for further replies.

joe33

Beta member
Messages
2
I have a field called field@code1 in a form in a XSL page.

i want to use java script to do validation.

the javascript errors if there is a @ in it.

1. is there any way of putitng an @ in javascript
2. is there any other way i can referance the field.

thanks
 
Using the getElementById it can be done easily, one example below:

HTML:
<html>
  <head>
    <script type="text/javascript">
      function referenceMe( fieldID )
      {
        var field = document.getElementById( fieldID );
        alert( "The value of the field " + fieldID + " is: " + field.value );
      }
    </script>
  </head>
  <body>
    <input type="text" id="test@code" onkeyup="javascript:referenceMe( this.id )">
  </body>
</html>

Or if you wanted to pass the field id in the function itself, you'd just surround it with single quotes, eg:
onkeyup="javascript:referenceMe( 'test@code' )"

Sorry, this wasn't all too quick. :p
 
Status
Not open for further replies.
Back
Top Bottom