All,
I've a javascript routine which returns a string value, I want to use this routine inside my html tags like this,
<a href="#"><script>getKeyValue('empDesignation')</script></a>
Is this possible?. Any insights?
All,
I've a javascript routine which returns a string value, I want to use this routine inside my html tags like this,
<a href="#"><script>getKeyValue('empDesignation')</script></a>
Is this possible?. Any insights?
<html>
<head>
<script type="text/javascript">
function alterText(){
document.getElementById('hello').innerHTML = empDesignation();
}
function empDesignation(){
var output = 'test'
return output
}
</script>
</head>
<body onload="javascript:alterText()">
<a id="hello"></a>
</body>
</html>
This should work. I had to mock up your empDesignation function.
document.write(getKeyValue('empDesignation')); This would probably do the trick.
UPDATE: It has to be enclosed within <script> tags
no you cant use javascript variables inside html tags. You have to set the value to html by using DHTML.
If you post some code i can help you
You can do
var txt = getKeyValue('empDesignation');
$('#result').text(txt);
This assumes that getKeyValue() returns a string. Then you put that the result as text of element with id=result
EDIT - after your edit. you could do
HTML
<a href="#" data-key='empDesignation' class='functional'>your text</a>
js
//when you click on a link that has the class functional
$('a.functional').on('click', function(e){
//prevent the default action
e.preventDefault();
//retrieve the data that from the html5 data attribute and pass it to
//your custom function
var result = getKeyValue($(this).data('key'));
//use the resulting string as the new text for the clicked link
$(this).text(result);
})
inside html tags this getKeyValue('empDesignation') it is not possible,
use innerHTML like below example
<html>
<script type="text/javascript">
function changeText(){
document.getElementById('boldStuff').innerHTML = 'is Software Developer';
}
</script>
<body>
<p>Employee Designation <b id='boldStuff'>is what?</b> </p>
<input type='button' onclick='changeText()' value='Change Text'/>
</body>
</html>
EDIT
<script type="text/javascript">
function changeText(){
var get_des=getKeyValue('empDesignation');
document.getElementById('change_id').innerHTML = get_des;
}
</script>
<a href="#" id="change_id" onclick='changeText()'></a>