Can I access the function body of an event listener using nodeJS jsdom - dom

I am using jsdom with nodeJS. I load in a large HTML document, and am using jQuery to navigate the DOM. I have a case where I have an element, and I need to access the function body of an event listener (onclick). The event listener was added in the source HTML:
The onclick attribute of the DOM element is undefined.
btw: what I really want to do is get the URL (please note that <rest-of-url> is not what is in the source, a real URL spec is there) that is specified in the source.

e.getAttribute('onclick') doesn't work?

Related

Dynamically loading content through Groovy server page upon form submit

I have a Groovy project (vanilla; no Grails) with an index.gsp that takes form input from the user and sends it in a POST request to a Groovy script. The form is set up like this:
<form action="somewhere" method="POST" enctype="multipart/form-data">
// some other inputs
<input type="submit"/>
</form>
Is there any way (ideally not using Javascript) to dynamically load content on the same page after the user submits? Redirecting to another GSP might also work. Just something simple, like a string containing whatever the user typed. It seems like Grails has plenty of options, but unfortunately I can't use it.
As you mentioned, Grails is capable of doing what you need without any complex code. Since you can't use it, you will have to use JQuery(Javascript) to make an AJAX call. AJAX is the he only way that I know to achive that.
Just make an AJAX call to your groovy script. JQuery.ajax has a success function to be called if the request succeeds. You can use it to update a hidden dive after the form. This success function has the data returned from the server as an argument, that data could be the string containing whatever the user typed. In that case just add the data to the hidden div and then make that div visible.
function onSucceed(data) {
$('#hiddenDivToUpdate').text(data);
$('#hiddenDivToUpdate').show();
}
You can learn about JQuery.ajax() in this link AJAX

Allow form submission to server inside of angularJS?

According to the AngularJS doc's https://docs.angularjs.org/api/ng/directive/form
"For this reason, Angular prevents the default action (form submission to the server) unless the element has an action attribute specified."
is there any way to stop angularJS doing this?
If you don't want the form submission to go down the browser handled route don't put the action attribute on the form use the directive ng-submit which basically calls a method on your controller which will allow you to send the data to the server via a xhr request.

loading html FORM asynchronously and adding it into DOM does'nt get validated by jQ validation plugin

A simple get request made to url on my server which returns HTML of form which is put inside td element .
$('form').validate(); // jquery validation plugin initialized
//user clicks some button and ajax request is send to load form
$.get(url,send,function(form){
$('td').html(form).show();
});
Problem is validation plugin do not work on the loaded form ?
The form you are trying to validate does not exist when you initialise the plugin. Place the initialisation code in the success handler of the $.get(...).

Yii - How to call external javascript on every CActiveForm validation?

I would like to make a "preview container" for form values in Yii. (so every time the user finishes entering data, the "preview container" below the form will display them, to let the user knows how the item actually looks like).
To achieve this, the only way is to call a Javascript function to update the "preview container" (using jQuery). The CActiveForm is:
<?php
$form = $this->beginWidget('CActiveForm', array(
'id'=>'item-form',
'enableAjaxValidation'=>true,
));
?>
How do we modify it to call a javascript function each time the fields are validated?
(Note: whenever we switch between the input fields, the fields are validated dues to enableAjaxValidation=>true)
Thanks in advanced.
With jQuery you can define your own listener functions for the fields you want to update, which is probably going to be cleaner than trying to hook into the validation functions.You could monitor onchange or blur or whatever is most appropriate to your data.
The js can be loaded via Yii's registerScript function or, again, whatever is most appropriate for your app. A listener function would normally be loaded on DOM ready, i.e., with the POS_READY attribute for registerScript.
You can search the tutorials as well as this basic tutorial for more info.

How do you access Content of an Iframe using GWT?

I have a HiddenIframe that i created in GWT which gets response from a post.
OnBrowsewerevent() i try to introspect the contents of Iframe for a error code or success.
When i access the Iframe via GWT, I can access it but innerHTML method always null
I write a JSNI method
private native String getMessage()/*-{
var e = document.getElementById('my_iframe');
var html = e.contentWindow.document.body.innerHTML;
return html
}-*/;
I always get e as null as GetelementbyID is returning null, When i introspect HTMLusing firebug i can see the Iframe with the ID. What is the best way to solve the problem?
You need to use the GWT specific $doc variable, instead of document. From the GWT JSNI documentation:
When accessing the browser's window and document objects from JSNI, you must reference them as $wnd and $doc, respectively. Your compiled script runs in a nested frame, and $wnd and $doc are automatically initialized to correctly refer to the host page's window and document.