Calling JSF methods from pure JavaScript [duplicate] - javascript

This question already has answers here:
Calling Managed Bean Method From JavaScript [duplicate]
(6 answers)
How to invoke a JSF managed bean on a HTML DOM event using native JavaScript?
(1 answer)
Invoke JSF managed bean action on page load
(4 answers)
Closed 5 years ago.
here is my problem. I have this xhtml page:
<html>
<body>
<script>
function myFunction() {
var link='#{myController.goMyDetails}' + MyId
var MyId = '#{myController.myDetails.getId()}';
self.location=link;
}
</script>
<input type="button" id="LinkBtn" onclick="myFunction()" value="Go Details" />
</body>
</html>
What I need it to do is open itself again but with the called Controller.goMyDetails and the Id in MyId as parameter for the controller.
So I click the button and I get the Controller.goMyDetails called with MyId as parameter.
Is there anyway to do this with javascript. No Primefaces or other stuff.
Thank you for your help, this is driving me mad.

Related

form onsubmit delaying window.open not working [duplicate]

This question already has answers here:
Prevent form redirect OR refresh on submit?
(7 answers)
Closed 2 years ago.
I have been trying to figure this out for past few hours, I have form and when users will submit it,
new window popup will occur, however I want it delayed slightly, setting setTimeout did not work and I have no idea why.
example:
<form method="post" target="print_popup" action="https://example.com" onsubmit="window.open('about:blank','print_popup','width=1000,height=800');">
<input type="hidden" name="param" value="foobar">
<input id="1" type="submit" value="Submit request">
Think you will need to set the target attribute of the form to _blank to allow for opening a new context:
https://developer.mozilla.org/en-US/docs/Web/HTML/Element/form
I would also check chrome/your choice of browser isn't blocking your popup

Why doesn't onClick activate function? [duplicate]

This question already has answers here:
Why does jQuery or a DOM method such as getElementById not find the element?
(6 answers)
Closed 6 years ago.
I'm trying to write a simple code in JavaScript where selecting a button calls a prompt function, but the prompt never pops.
This is the HTML:
<div id="btnDiv">
<button type="submit" id="btn" onclick="submit"> send info </button>
</div>
And this is the JavaScript code:
document.getElementById("btn").onclick = function(){
prompt("Thank you");
}
What am I doing wrong?
Make sure that the JS code is loaded after the HTML content, you can use onLoad event:
window.onload=function(){
document.getElementById("btn").onclick = function(){
prompt("Thank you");
}
};

How to submit HTML multiple forms generated by jQuery [duplicate]

This question already has answers here:
Event binding on dynamically created elements?
(23 answers)
Closed 6 years ago.
On ajax success i have list of generated forms:
...
success: function (data) {
$el.append('<form method="POST" class="submit_form">Name: '+data[i].namen+'
Id: '+data[i].id+'<br> SomethignElse: <label id="red">'+data[i].se+'</label><br> SomethingElse2: '+data[i].se2+'
<input type="text" name="id" value="'+data[i].id+'" id="id_test" />
<input type="button" class="submit_button1" value="Add"/></form><br>');
i = ++ i;
}
...
Also i have a click functionto submit this forms/form:
$(".submit_button1").click(function(){
//do something
});
but nothing happens on click. Is it possible to submit in this way?
Please try .on('click' event listner.
$(document).on('click','.submit_button1',function(){
//do something
});

getelementbyid returns null in asp server page [duplicate]

This question already has answers here:
ASP.Net First inner form in Server Form doesn't POST
(2 answers)
Forcing client ids in ASP.NET
(6 answers)
Closed 8 years ago.
I am trying to grab a form inside a usercontrol with asp server pages.
I have tried multiple things but without luck.
<tr id="trManageAddress" runat="server" visible="false">
<td>
<form id="addressForm">...form here....</form>
<script type="text/javascript">
var addressForm = document.getElementById("addressForm");
if (addressForm == null)
alert("null");
else
alert("good");
</script>
</td>
</tr>
However the alert keeps returning with null.
I don't see what I am doing wrong here?
Note Before testing, an other piece of code sets trManageAddress visible to true.
Edit I got noticed I shouldn't include a second form but use the form in the master page, the issue is solved now I can successful access the masterpage form.

Cannot programmatically submit form [duplicate]

This question already has answers here:
"Submit is not a function" error in JavaScript
(19 answers)
Closed 8 years ago.
Cannot get my form to submit programmatically, despite trying several ways. Tried pure JS, also tried jQuery. No success.
I have this form tag :
<form action="https://docs.google.com/forms/d/13zex8ZsEsnZz3A8uB4jU4oDb5wZfaqqq2Pq2CGlIe6M/formResponse" method="POST" id="ss-form" target="_self" onsubmit="" name="eForm">
<!--My Form Stuff-->
<input type="submit" name="submit" value="Submit" id="ss-submit">
</form>
Here is what i've tried :
/*jQuery*/
$('#ss-form').submit();
/*Javascript*/
document.getElementById('ss-form').submit();
document.eForm.submit();
None of them work. Not sure why, but I am assuming it has something to do with me trying to submit a google form. If I physically click the submit everything works fine.
Any and all help is greatly apprecaiated.
The problem is that you have a field (HTMLInputElement) with name submit in the form. That's why document.getElementById('ss-form').submit is not a function but an object.
So, you get the following error:
TypeError: object is not a function
The solution is to remove that element. We should be careful to verify if browser thinks it's an element and not a function:
if (typeof document.getElementById('ss-form').submit === "object") {
document.getElementById('ss-form').submit.remove();
}
document.getElementById('ss-form').submit();

Categories

Resources