How to change message text in JSP from javascript?
Matthew Barrera
I'm javascript newbie, so excuse me :)
I've got following in my SomePage.jsp:
<div title="Some title"> <p> <span></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.
22 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 title="Some title"> <p> <span></span>
<span>
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>
MESSAGE_TO_REPLACE
</span></p>js code:
if (SOME_FLAG) { $("#prompt-form p span").html("11"); } else { $("#prompt-form p span").html("12"); }