javascript - Updating an html "value" with a jquery variable -
javascript - Updating an html "value" with a jquery variable -
so i'm building messaging application in user clicks on button, jquery prompt displayed asking user type in message, , ideally message sent using separate ajax function.
here code in question:
jquery message prompt function:
function getinput() { var text = prompt("enter message", ""); if (text != null) { document.getelementbyid("demo").innerhtml = text; //failed effort @ updating value using id of input. } }
html:
<form name="messagesend" method="post" onsubmit="return sendmessage(this);"> <input type="hidden" id="demo" name="message" value="i want update field result of javascript text variable" /> <input type="hidden" name="regid" value="<?php echo $row["gcm_regid"] ?>"/> <input type="submit" class="send_btn" value="volume-vibrate" onclick="getinput()"/> </form>
as can see, field want update string contained in value
message beingness sent. how update result of whatever user puts in text prompt?
any help appreciated!
edit:
updated jquery function following:
function getinput() { var text = prompt("enter message", ""); if (text != null) { $("#demo").val(text); } }
this may different question, when button created in html posted clicked, displays prompt , type in message, default value placed still message beingness sent.
onsubmit="return sendmessage(this);"
being executed before jquery updating value field? , if so, there anyway prepare that?
if helps, here sendmessage
uses ajax send off message php script. html value
field (which i'm trying user-input string jquery prompt using getinput()
) becomes data
variable, contains registration id of designated recipient of message.
function sendmessage(formobj){ var info = $(formobj).serialize(); $(formobj).unbind('submit'); $.ajax({ url: "send_message.php", type: 'get', data: data, beforesend: function() { }, success: function(data, textstatus, xhr) { $('.txt_message').val(""); }, error: function(xhr, textstatus, errorthrown) { } }); homecoming false; }
a html field doesn't have inner html (the tag self-closing), has value (and value
property).
but you're using jquery, should utilize functions anyway: $("#demo").val(text)
javascript jquery html
Comments
Post a Comment