Eddie Shipman
asked on
Refreshing after innerText changed?
Got the following javascript in one of my pages to update the label for a textarea when a user selects a particular
option from a select. how do I make the label change and it be reflected in the page?
function output()
{
var usage;
qs_enginename = document.getElementById('q search_sel ect').valu e;
if (qs_enginename == 'siteauthor')
{
usage = "Usage: keyword(s) author:username";
} else {
usage = "Usage: keyword(s)";
};
document.getElementById("u sage").inn erText = usage;
// The alert box correctly shows the innerText I want but
// the Label DOES NOT CHANGE
alert(document.getElementB yId("usage ").innerTe xt);
}
HTML:
<form id="qsearch_form" method="post" action="search.php" onsubmit="return qsearch_onSubmit();">
<p>
<input type="text" tabindex="6" name="keywords" id="searchfield" size="22" maxlength="40" title="searchkw" value="" />
</p>
<p>
<select id="qsearch_select" tabindex="7" onChange="output()">
<optgroup label="SITE">
<option value="site">Posts</option >
<option value="siteauthor">Posts by Author</option>
<option value="author">Author</opt ion>
</optgroup>
<optgroup label="ENGINE">
<option value="wikipedia">Wikipedi a</option>
<option value="google">Google</opt ion>
<option value="yahoo">Yahoo</optio n>
<option value="msnlive">MSNlive</o ption>
<option value="altavista">Altavist a</option>
<option value="lycos">Lycos</optio n>
<option value="odp">Open directory</option>
</optgroup>
</select>
<input type="hidden" name="search_fields" value="all" />
<input type="hidden" name="show_results" value="topics" />
<input type="submit" value="sh" class="button2" tabindex="8" />
</p>
<label for="searchfield" id="usage">Usage: keyword(s)</label>
<br />
</form>
option from a select. how do I make the label change and it be reflected in the page?
function output()
{
var usage;
qs_enginename = document.getElementById('q
if (qs_enginename == 'siteauthor')
{
usage = "Usage: keyword(s) author:username";
} else {
usage = "Usage: keyword(s)";
};
document.getElementById("u
// The alert box correctly shows the innerText I want but
// the Label DOES NOT CHANGE
alert(document.getElementB
}
HTML:
<form id="qsearch_form" method="post" action="search.php" onsubmit="return qsearch_onSubmit();">
<p>
<input type="text" tabindex="6" name="keywords" id="searchfield" size="22" maxlength="40" title="searchkw" value="" />
</p>
<p>
<select id="qsearch_select" tabindex="7" onChange="output()">
<optgroup label="SITE">
<option value="site">Posts</option
<option value="siteauthor">Posts by Author</option>
<option value="author">Author</opt
</optgroup>
<optgroup label="ENGINE">
<option value="wikipedia">Wikipedi
<option value="google">Google</opt
<option value="yahoo">Yahoo</optio
<option value="msnlive">MSNlive</o
<option value="altavista">Altavist
<option value="lycos">Lycos</optio
<option value="odp">Open directory</option>
</optgroup>
</select>
<input type="hidden" name="search_fields" value="all" />
<input type="hidden" name="show_results" value="topics" />
<input type="submit" value="sh" class="button2" tabindex="8" />
</p>
<label for="searchfield" id="usage">Usage: keyword(s)</label>
<br />
</form>
ASKER
No I didn't try and I'm using FF3 so it should have worked.
How would I rewrite it so it'd work for all browsers?
How would I rewrite it so it'd work for all browsers?
I gave the example of how it should work in all the broswers:
var selectBox = document.getElementById('q search_sel ect');
qs_enginename = selectBox.options[selectBo x.selected Index].val ue
var selectBox = document.getElementById('q
qs_enginename = selectBox.options[selectBo
ASKER
This code still doesn't refresh in FF3
function output()
{
var usage;
var selectBox = document.getElementById('qsearch_select');
var label = document.getElementById('usage');
qs_enginename = selectBox.options[selectBox.selectedIndex].value
if (qs_enginename == 'siteauthor')
{
usage = "Usage keyword(s) ^username";
} else {
usage = "Usage keyword(s)";
};
label.innerText = usage;
}
ASKER
alert(usage);
Shows the correct text.
Shows the correct text.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
It may not working because this line may not be supported in your browser:
qs_enginename = document.getElementById('q
var selectBox = document.getElementById('q
qs_enginename = selectBox.options[selectBo
You may also try innerHTML instead of innerText