how to set variable value in form action? - javascript

is it possible to set variable value in html form action?
var serverUrl=homeURL + "/runapp?requestType=Import&subRequestType=importScenario&userName=";
refButton = '<form id="importForm" action="serverUrl" class="userInputForm" enctype="multipart/form-data" method="post">' +
'<input id="file" name="file" type="file" />' +
'</form>';

You mean insert the value of the variable? Why wouldn't it? In this case you're creating an HTML string to return, so something like this should work:
returnedHTML = '<form action="'+JSvariable+'" id="myId>
or
returnedHTML = '<form action="<?=$phpVariable?>" id="myId>

Related

How to Add javascript variable inside html attribute

I have a form and I want to add javascript variable inside the value="". value="embedurl"
I am new to adding javascript variable inside html, so far, all of the solutions that i found on google is not working. How to do this? Thanks.
<form id="landing2" action="https://example.com/post10/" method="post">
<input type="hidden" name="name" value=" var embedurl ">
<input type="submit">
</form>
<script>
var embedurl ="https://" + document.location.host + "/embed" + window.location.pathname;
document.getElementById('landing2').submit();
</script>
Try this ,
var embedurl ="https://" + document.location.host + "/embed" + window.location.pathname;
document.getElementsByName("name")[0].value = embedurl; // here you need to set the input value
document.getElementById('landing2').submit();
If you want to add a javascript value, you must do it by javascript.
First, you need to get the dom input element, then set the value
var form = document.getElementById("landing2");
var input = form["name"];
input.value = embedurl;

URL Encoding : Javascript

I have a javascript capturing signatures and data.
The " are getting lost/cutoff and not conserving. I assume this is a URLEncoding issue.
This is the original.
'<input type="hidden" name="rvnotes" value="' + rvnotes + '"/>' +
And I have tried this, but still no luck. Any idea how to URL Encode the Javascript submission.
'<input type="hidden" name="rvnotes" value="' + encodeURIComponent(rvnotes) + '"/>' +
The trick must be done in <form>.
<form enctype="application/x-www-form-urlencoded" ...>

submit to a spring controller from a javascript code

I am trying to submit a form to a controller from a javascript but the form button is not showing.
This is my attempt
for (var i = 0; i < json.length; i++) {
users += '<strong>' + json[i].email + '</strong><br/>' + '<br/>' + json[i].tok + '<hr><br/>';
//trying to hit to the controller from here but it is not working
//trying to hit to the controller from here but it is not working
'<form method="post" action="searchAdmin" novalidate="novalidate">'
'<input type="email" value="json[i].email" name="searchName" id="searchName"/>'
//on clicking the fetch button let it submit to the controller
'<input type="submit" value="FETCH" />'
'</form>'
Kindly assist!
user+='<form met....
because you have used ; on the first line so you need to append this string
Could you try making the form a single string? Try like below;
//trying to hit to the controller from here but it is not working
'<form method="post" action="searchAdmin" novalidate="novalidate"><input type="email" value="json[i].email" name="searchName" id="searchName"/><button type="submit">FETCH</button></form>'

faceMocion input tag not get bind in jQuery

when i use <input type="hidden" value="asombro" class="facemocion" /> in body then its work correctly ,
but when i try to bind same tag with jQuery like
html= html + "<input type="hidden" value="asombro" class="facemocion" />"
it not get work
You will need to use single quotes for the string:
html += '<input type="hidden" value="asombro" class="facemocion" />';
Or escape the double quotes inside it:
html += "<input type=\"hidden\" value=\"asombro\" class=\"facemocion\" />";
You can do it like more jquery way rather than creating it as string,
var hidden = $("<input>", {
type: 'hidden',
value: 'asombro',
'class': 'facemoion'
});
$("body").append(hidden);
Try make this way.
html += '<input type="hidden" value="asombro" class="facemocion"/>
$('body').append(html);
now use the plugin.
$('.facemocion').faceMocion();

How can I return an array from an object key value in JavaScript?

So I have the following piece of code:
var structures = {
loginStructure : function(){
return structure = [
'<form name="',opts.formClass,'" class="',opts.formClass,'" method="post" action="#">',
'<fieldset class="',opts.fieldsWrapper,'">',
'<fieldset class="',opts.userWrapper,'">',
'<label for="',opts.userInt,'" class="',opts.userLbl,'"><img src="',opts.userIcon,'" alt="',opts.userName,'" /></label>',
'<input type="text" name="',opts.userInt,'" class="',opts.userInt,'" placeholder="',checkNameLenght(opts.userName,namesLenght.userNameLenght,16,'Username'),'" value="" autocomplete="off" />',
'</fieldset>',
'<fieldset class="',opts.passWrapper,'">',
'<label for="',opts.passInt,'" class="',opts.passLbl,'"><img src="',opts.passIcon,'" alt="',opts.passName,'" /></label>',
'<input type="password" name="',opts.passInt,'" class="',opts.passInt,'" placeholder="',checkNameLenght(opts.passName,namesLenght.passNameLenght,16,'Password'),'" value="" autocomplete="off" />',
'</fieldset>',
'<fieldset class="',opts.btnWrapper,'">',
'<button type="submit" name="',opts.btnInt,'" class="',opts.btnInt,'">',checkNameLenght(opts.btnName,namesLenght.btnNameLenght,7,'Login'),'</button>',
'</fieldset>',
'</fieldset>',
'<div class="toogle-button">',
'<ul class="inside">',
'<li class="toogle"><a><img src="assets/gfx/toogle.png" alt="Back" /></a></li>',
'</ul>',
'</div>',
'</form>',
'<div class="toogle-buttons">',
'</div>'
];
}
}
This returns ( if I do console.log(structures.loginStructure) ) just a function(). Is there a way I can make it to return the actual array I have in there ?
The purpose of it would be to have multiple arrays defined as object keys, if it is possible to return such a thing, because it seems easier. Or is there a better way to do this ?
You want:
structures.loginStructure();
structures.loginStructure is simply just returning a reference to the function, instead of executing the function and returning its result. Add the () to the end of it to execute it and return its result.
Alternatively, and maybe better, don't write it as a function. Just declare loginStructure: ['<form name.... Basically, just remove function(){return structure =. A significant difference to note here is that any values of opts would be evaluated immediately, instead of deferred until later when then function would be executed - so please don't blindly update your code to this.

Categories