leawasson
asked on
Change checkbox text onchange with javascript
I have the following checkbox:
<c:set var="value" value="${form.flagNpOrSp}" />
<input type="checkbox" name="flagNpOrSp" value="on" <c:if test="${value}">checked="c hecked" </c:if> id="searchFlagNpOrSp"/>
<c:set id="searchFlagNpOrSpCaptio n" var="value" value="${form.flagNpOrSpCa ption}"/>
<c:out value='${value}' />
How can I change the the label of the checkbox based on what a user select in a dropdown?
<c:set var="value" value="${form.flagNpOrSp}"
<input type="checkbox" name="flagNpOrSp" value="on" <c:if test="${value}">checked="c
<c:set id="searchFlagNpOrSpCaptio
<c:out value='${value}' />
How can I change the the label of the checkbox based on what a user select in a dropdown?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Bugs, please enlighten us and explain what this code is doing?
eval("document.myForm.flag NpOrSp.che cked = false");
???
and what is the [lvl-1]; doin in the following?
var text =
[
"Sentence relating to option 1",
"Sentence relating to option 2",
"Sentence relating to option 3"/**/
][lvl-1];
and lastly why remove and append when you can change the innerHTML of the span???
eval("document.myForm.flag
???
and what is the [lvl-1]; doin in the following?
var text =
[
"Sentence relating to option 1",
"Sentence relating to option 2",
"Sentence relating to option 3"/**/
][lvl-1];
and lastly why remove and append when you can change the innerHTML of the span???
PS: Is this not a duplicate of
https://www.experts-exchange.com/questions/22766203/Using-Javascript-to-change-text.html
??
https://www.experts-exchange.com/questions/22766203/Using-Javascript-to-change-text.html
??
@mplungjan
I was trying to give an example of how to go about it and not exactly working example to do the code. It would just enlighten the coder to enhance it.
Cheers
I was trying to give an example of how to go about it and not exactly working example to do the code. It would just enlighten the coder to enhance it.
Cheers
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
@mplungjan
And the second section got accidentally placed here....i could not remove it....i apologies...
And the second section got accidentally placed here....i could not remove it....i apologies...
ASKER
This was exactly what I was looking for. Thank you very much!
Great...
It was a variation of b0lsc0tt's code so perhaps he deserved a split?
Michel
It was a variation of b0lsc0tt's code so perhaps he deserved a split?
Michel
Thanks Michel (not just for the last post). ;-)
Leawasson, no worries about the split. If you have a question about what a split is though let us know.
bol
Leawasson, no worries about the split. If you have a question about what a split is though let us know.
bol
ASKER
That is true. So sorry b0lsc0tt. I am new to the site and only realized later that you could accept multiple answers. Unfortunately it seems you can't do anything after the fact! *Michelle mentally deducts points from Michel's next accepted answer* :) Thanks to everyone for their help.
I'm glad you know now. That is most important.
For future info you can have a question reopened or get help changing what you did to close it. You just post a message in the General Community Support zone (https://www.experts-exchange.com/Community_Support/General/). You can even save this page (https://www.experts-exchange.com/Community_Support/General/newQuestionWizard.jsp) to automatically be taken to the question wizard for that zone.
No points are needed for posting. The moderators and admins respond to posts and are VERY helpful. Make sure you include the URL for the question in the message body and provide the details of what you need. You don't have to use it for this question but this is good info to have. Let me know if you have a question.
bol
For future info you can have a question reopened or get help changing what you did to close it. You just post a message in the General Community Support zone (https://www.experts-exchange.com/Community_Support/General/). You can even save this page (https://www.experts-exchange.com/Community_Support/General/newQuestionWizard.jsp) to automatically be taken to the question wizard for that zone.
No points are needed for posting. The moderators and admins respond to posts and are VERY helpful. Make sure you include the URL for the question in the message body and provide the details of what you need. You don't have to use it for this question but this is good info to have. Let me know if you have a question.
bol
Thanks for taking the extra time and effort to split this. It was a fun question. Thanks for the grade and the points.
bol
bol
<script language="javascript">
function changeValue(){
eval("document.myForm.flag
}
</script>
To change the label of the checkbox based on the dropdown selection use....
Here goes an example for you...
<html>
<head>
</head>
<body>
<table width="680" border="0" cellpadding="0" cellspacing="0">
<tr align="left" valign="top">
<td>
<p id="example3">I want to replace this text: <span id="ex3Span">right here </span>.</p>
<script type="text/javascript">
/*! sent 'this.selectedIndex' as parameter in call */
function replaceSpan(lvl)
{
// An array is easier to edit.
// Here it's defined and used at the same time.
var text =
[
"Sentence relating to option 1",
"Sentence relating to option 2",
"Sentence relating to option 3"/**/
][lvl-1];
var span = document.getElementById("e
while(span.childNodes[0]) /* removing nodes */
span.removeChild(span.chil
span.appendChild(document.
}
</script>
<SELECT NAME = "option3" id="option3" onChange="replaceSpan(this
<OPTIon VALUE = "1">Option 1
<OPTIon VALUE = "2">Option 2
<OPTIon VALUE = "3">Option 3
<OPTIon VALUE = "4">Option 4
</SELECT>
</td>
</tr>
</table>
</body>
</html>