How to Change Message Text in Jsp from Javascript?
I'm Javascript Newbie, So Excuse Me:) I've Got Following in My Somepage. Jsp: Message_To_Replace and I'm Using Following Javascript Code: $("#Prompt-Form")...
I'm javascript newbie, so excuse me :)
I've got following in my SomePage.jsp:
<div id="prompt-form" title="Some title">
<p> <span class="ui-icon ui-icon-comment" style="float:left; margin:0 8px 35px 0;"></span>
MESSAGE_TO_REPLACE
</p>
</div>
And I'm using following javascript code:
$("#prompt-form").dialog({
autoOpen: false,
resize: "auto",
modal: true,
buttons: {
Yes: function () {
if (SOME_FLAG) {
MESSAGE_TO_REPLACE = "11";
} else {
MESSAGE_TO_REPLACE = "12";
}
},
No: function () {
$(this).dialog("close");
}
},
open: function () {
$(":button:contains('No')").focus();
}
});
The question is, how to send new message text from my javascript code (this file is not build in my SomePage.jsp) to SomePage.jsp ?
Is it real ?
Thanks for everyone.
2 Answers
I m not getting what you are trying to say... If you want to change text "MESSAGE_TO_REPLACE" use following code otherwise ignore it.. :)
<div id="prompt-form" title="Some title">
<p> <span class="ui-icon ui-icon-comment" style="float:left; margin:0 8px 35px 0;"></span>
<span id="msgToReplace">
MESSAGE_TO_REPLACE
</span>
</p>
</div>
<script>
document.getElementById("msgToReplace").innerHTML = "newText";
</script>
You can use jquery selector to find the element which html you need to change. Then use $.html() to change it. The span tag should enclose the message, so you can replace the body.
html code:
<p> <span class="ui-icon ui-icon-comment" style="float:left; margin:0 8px 35px 0;">
MESSAGE_TO_REPLACE
</span></p>
js code:
if (SOME_FLAG) {
$("#prompt-form p span").html("11");
} else {
$("#prompt-form p span").html("12");
}