I am creating dynamic form in JavaScript. I want to send the data's from JavaScript to servlet. I dont use any submit Button in my Form.Using button only i want to send the data's. Anyone help me please.
This is my code:
var myform=document.createElement("form");
myform.setAttribute("id", "myform");
var tname=document.createElement('input');
tname.setAttribute('type','text');
tname.setAttribute('name', "name");
var leaveMessage=document.createElement('input');
leaveMessage.setAttribute('type','button');
leaveMessage.setAttribute('name', "msgButton");
leaveMessage.setAttribute('value', "Leave Message");
myform.appendChild(tname);
myform.appendChild(leaveMessage);
document.body.appendChild(myform);
add some statements also
var myform=document.createElement("form");
myform.setAttribute("id", "myform");
myform.setAttribute('action', "/mypage");
myform.setAttribute('method', "post");
var tname=document.createElement('input');
tname.setAttribute('type','text');
tname.setAttribute('name', "name");
var leaveMessage=document.createElement('input');
leaveMessage.setAttribute('type','button');
leaveMessage.setAttribute('name', "msgButton");
leaveMessage.setAttribute('value', "Leave Message");
myform.appendChild(tname);
myform.appendChild(leaveMessage);
document.body.appendChild(myform);
document.forms["myform"].submit();
Related
Field Dep_rev contain of
I only manage to using xpages JavaScript to send one user only.
method : maildoc.replaceItemValue("SendTo",document1.getItemValueString("Dep_rev"));
Below is my coding
var maildoc:NotesDocument = database.createDocument();
maildoc.replaceItemValue("Form", "Memo");
maildoc.replaceItemValue("Subject", "Testing mail");
session.setConvertMime(false);
var stream = session.createStream();
stream.writeText("<html><body>");
stream.writeText("<p>Testing</p>");
stream.writeText("</body></html>");
var body = maildoc.createMIMEEntity("Body");
body.setContentFromText(stream, "text/html;charset=UTF-8", 1725);
stream.close();
maildoc.closeMIMEEntities(true);
session.setConvertMime(true);
maildoc.replaceItemValue("SendTo",document1.getItemValueString("Dep_rev"));
maildoc.send();
Just use getItemValue:
maildoc.replaceItemValue("SendTo",document1.getItemValue("Dep_rev"));
As an alternative you can use copyItem:
maildoc.copyItem(document1.getDocument().getFirstItem("Dep_rev"), "SendTo");
I have a form created dynamically with one input:
var myForm = document.createElement('form');
myForm.setAttribute('id', 'formDynamically');
myForm.method = 'POST';
myForm.action = 'myAction';
var myInput = document.createElement('input');
myInput.type = 'text';
myInput.name = 'textDescription';
myInput.value = $('#myTextField').text();
myForm.appendChild(myInput);
document.body.appendChild(myForm);
myForm.submit();
My problem is:
If the user types a text with accentuation, in the server the letters arrive strange
Exemple:
'fiancé'. in the server side i recived ---> 'fiancé'
obs: I can't change anything in server side.
obs²: I tried it with Jquery Ajax and works fine, the problem really is with my form (i can't use ajax, i must do it with form submit).
Any help is welcome !
Try this :
myForm.acceptCharset = "UTF-8";
Documentation
I want to submit a form and another textarea on my ajax post, will that be possible? Here is my code
<script>
function updateuseracc(form, password)
{
var p = document.createElement("input");
form.appendChild(p);
p.name="p";
p.type="hidden";
p.value=hex_sha512(password.value);
password.value="";
var email=$("#curemail").val();
$.post('updateuser.php',$('#myform').serialize(),textarea:textarea),(function(data){
});
}
</script>
I'm just getting errors with this
First textarea is not a variable. If you want to get the value of it do this:
var text = $(textarea).text ();
Put data in curly braces, function is third parameter.
$.post('updateuser.php', {
form:$('#myform').serialize(),
textarea:text},
function(data){
//code...
});
In addition, you should take care of ANY security features on the server side!
http://api.jquery.com/jquery.post/
I currently have a form with some JavaScript functions and localstorage.
I'm trying to get that when a user types a value into a textbox, the search bar changes the URL from "mysite.com" to "mysite.com/%userinput%". Then that user can send that link to someone else and that person will then see what the original user saw.
This will change the URL after input.
As I understand from your question and comments, you don't want to load the URL, just change it, so try this fiddle: http://jsfiddle.net/GrP6U/2/show/
The code behind is:
JavaScript
var theForm = document.getElementById('theForm');
var theInput = document.getElementById('subj');
theForm.onsubmit = function(e) {
var myurl = "http://jsfiddle.net/GrP6U/2/show/?input=" + encodeURIComponent(theInput.value);
window.history.pushState('', "Title", myurl);
return false;
}
HTML
<form id="theForm">
<input id='subj'/>
<input type='submit'/>
</form>
I'm trying to submit a JSP page after retrieving a variable from the javascript function with onclick. Is there a way to do that?
Javascript:
function sub(str)
{
alert(str); //To test if I am getting the variable on this function
}
JSP contents:
<c:forEach items="${mybean.flag}" var="element">
${element.CASE}
</c:forEach>
<%String w = request.getParameter("str");
if(!w.equals("null") {
Call a java bean to do further manipulations
}
%>
To submit a form per Javascript, you could do anytime the following:
document.forms[0].submit(); // assuming you have at least one Form on your page and want to submit the first one
I was able to do pass the variable from onclick using the below code.
Javascript:
function subb(str){
alert("Subb" +str);
form = document.createElement('form');
form.setAttribute('method', 'POST');
form.setAttribute('action', 'index.jsp');
myvar = document.createElement('input');
myvar.setAttribute('name', 'mydata');
myvar.setAttribute('type', 'hidden');
myvar.setAttribute('value',str);
form.appendChild(myvar);
document.body.appendChild(form);
form.submit();
}
${element.CASE}
</c:forEach>
<%String w = request.getParameter("mydata");
if(!w.equals("null") {
Call a java bean to do further manipulations
}
%>