Reputation: 17882
I have an input box with an I.D. of "q" on my website...
By entering javascript into the URL bar I can change the place holder text (client side) to say "test"
javascript:void(document.getElementById('q').value='test');
Now if I wanted to make it say test (but in bold with html) how would I do that?? I tried:
javascript:void(document.getElementById('q').value='<b>test');
But that won't work.. it's a string! I don't know much javascript...
Thanks all!
Upvotes: 0
Views: 554
Reputation:
Here's some code that works:
<html>
<head>
<script type="text/javascript">
function setDefaultText (text) {
var elem = document.getElementById('q');
elem.value = text;
elem.style.fontWeight = 'bold';
}
</script>
<style type="text/css">
#q {
font-weight: bold;
}
</style>
</head>
<body onload="javascript:setDefaultText('test');">
<input id="q" />
</body>
</html>
NOTE: You can set the font-weight with CSS or JavaScript, but you don't need both.
Upvotes: 0
Reputation: 5290
try:
document.getElementById('q').style.fontWeight = 'bold';
EDIT:
it should work fine:
<a href="javascript:void(document.getElementById('q').style.fontWeight='bold');">bold</a>
<input type="text" id="q" value="some text" />
Upvotes: 3