Thursday 9 May 2013

Replace labels text in form on load

<html>
<head>

<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
<script>

 var dictionary = new Array(); // for containing label texts and the text to be replaces
 dictionary['No1mbre'] = 'Number';   
 dictionary['Ogre'] = 'Age';  

//function for replacing text according to the attribute
//i use label attribute of table  , you can use any attribute in place of label

 $('document').ready(function(){
    
//     
 $('tbody').find('label').each(function(){
    if (dictionary[ $(this).text() ])
     {
         $(this).text( dictionary[ $(this).text() ] );
     }
 })

});

</script>
</head>
<body>
            <table>
            <tbody>
            <tr>
            <th>
            <label for="id_first_name" >No1mbre</label>
                <label for="id_first_name" >Age</label>
            </th>
            </tr>
            </tbody>
            </table>
</body>
</html>