Can I fill the form fields in iframe? - javascript

I have code to autofill form fields
(function( window ) {
"use strict";
var document = window.document,
fieldValueMap = {
"author" : "author"
, "name" : "name"
, "email" : "email#gmail.com"
, "url" : "url.link"
, "website" : "website.com"
, "comment" : "comment"
, "commentName" : "commentName"
, "commentEmail" : "commentEmail#gmail.com"
, "commentWebsite" : "commentWebsite.com"
, "commentComment" : "commentComment"
};
Object.keys( fieldValueMap ).forEach(function( name ){
var input = document.querySelector( "form input[id='" + name + "']" )
|| document.querySelector( "form select[id='" + name + "']" )
|| document.querySelector( "form textarea[id='" + name + "']" );
input && input.type !== "hidden" && ( input.value = fieldValueMap[ name ] );
});
})(window);
But it doesn't work properly when there is iframe on the website page.
It works only when I'm manually choosing "evaluation context" and put the code in console.
like that
result
So I wonder if there is a way to automatize the process of filling forms in iframe and make the whole script work together.
Perfectly I'd like to use final script as a bookmarklet.
My first coding experience, found the code on the internet and customized it for my needs. I'm sorry if the question is too stupid.
Any ideas?

Related

Trying to customize a pdf javascript to select compile variable emails for a submit button

THE BASICS:
So thanks to a number of online resources I found a way to make my pdf form SUBMIT button tied to a series of radio buttons. For example I have 3 radio buttons assigned to countries and each radio has at least one email address assigned to it. Based on the radio button selected the submit button will send the completed for to the target address(es). There's the code:
var nCountry = this.getField("Country").value;
if( nCountry == "US" ) event.value = this.submitForm
({cURL: "mailto:JohnDoe#abc.com; JaneDoe#abc.com", cSubmitAs: "PDF"});
else if( nCountry == "CA" ) event.value = this.submitForm
({cURL: "mailto:JohnDoe#abc.ca", cSubmitAs: "PDF"});
else if( nCountry == "MX" ) event.value = this.submitForm
({cURL: "mailto:JaneDoe#abc.com.mx", cSubmitAs: "PDF"});
So there has been a change and now they want to be able to send to more than just one country, for example the email can be sent to Canada AND Mexico. Unfortunately JS isn't my forte so I'm a bit out of my element. I think this would work by assigning the email addresses to the check boxes ands then having the JS compile all checked boxes but I'm not sure the syntax for this. So what I have so far is:
Set 3 check boxes to the same name 'Country'
Sent the Export value for each check box equal to the email address(es) I want
In the code set the this.getField to pull all exported values by the Country boxes
Submit to all compiled addresses
Something to the effect of this but I am aware my syntax is not correct. Hope this makes sense:
var nCountry = this.getField("US" + "CA" + "MX" ).value;
if( Country-US == "yes" ) US = "JohnDoe#abc.com; JaneDoe#abc.com"
if( Country-CA == "yes" ) CA = "JohnDoe#abc.ca"
if( Country-MX == "yes" ) MX = "JohnDoe#abc.mx"
event.value = this.submitForm
({cURL: "mailto:nCountry", cSubmitAs: "PDF"});
Is this easily doable?
Is there anywhere you could point me that may have this already explained?

Update form field based on another form field

I have 2 forms that each do specific calculations. On one of the forms (TCO), one of the input fields populates based on a input field in the other form(MORTGAGE).
The script I have below works fine --
<script>
function checkVar()
{
if( typeof myglobalvar != 'undefined' && myglobalvar != '' && myglobalvar != 0 && jQuery( '.mclass input' ).length )
{
jQuery( '.mclass input' ).val( myglobalvar );
fbuilderjQuery.fbuilder.calculator.defaultCalc( '#'+jQuery( '.mclass input' ).closest( 'form' ).attr('id') );
}
else
{
setTimeout( checkVar, 1000 );
}
}
checkVar();
</script>
In the first form, I have my equation for my calculations wrapped in another function --
(function(){
myvar = fbuilderjQuery.fbuilder.calculator.format( ROUND((fieldname17*(fieldname23/100)/fieldname12)), { 'groupingsymbol' : ',' } );
myglobalvar = myvar;
return myvar;
})()
Everything is working fine however when the value in the first form is changed or updated, the second form does not update.
Is there a way to add some kind of event/change listener for whenever the field updates?
EDIT:
using one of the suggestions in the comments below --
document.getElementById('fieldname22_7').addEventListener("oninput", function(evt) {
var Mor = document.getElementById('fieldname22_7').value;
document.getElementById('fieldname47_20').value = Mor; });
But I receive the follow error --
Uncaught TypeError: Cannot read property 'addEventListener' of null
Am I even close?
I can't fully understand your code, but I think, it could help you.
So. You have two forms like this:
<form>
<input id="input-1">
</form>
<form>
<input id="input-2">
</form>
And if the value of "input-1" changed, you want the "input-2" to be changed too.
In this case you should use the 'oninput' event.
So add an event handler to "input-1"
<input id="input-1" oninput="myEventHandler();">
And the event handler is:
<script>
function myEventHandler() {
var in = document.getElementById('input-1').value;
//Check the input
document.getElementById('input-2').value = in;
}
</script>
I hope it will help you!

How to access Javascript array using COM with Autohotkey

I've been using Autohotkey for a while to access some elements on a webpage, I can do so just fine using: wb.document.elements[x].forms[x].value and assigning this to a value. I apologize but my knowledge of Javascript is very limited.
Recently I looked at the code for the page and noticed the following:
<script type="text/javascript" defer="defer">
form = new ActiveForm('EditingServiceInformationforSOMEGUY','Editing Service Information for SOME GUY');
data = {};
data.header = ["addressid", "contactid", "address1", "address2", "city", "state", "zip"];
data.body = [["275101010", "254101010", "1001 Maudlin", "Apt. 1774", "Beverly Hills", "CA", "90210"]];
I have been unsuccessfully trying to access the data.body portion of this through AHK. If I type in the address bar while viewing the page:
javascript: alert(data.body[0])
I get a messagebox with the data.body values comma separated.
I can't seem to replicate this through Autohotkey. I've tried a lot of different syntax but I'm missing something here. I'd like to get a msgbox with the same values that I'm seeing in the Javascript Alert, and then further manipulate them from there.
I've tried many different combinations in my script to show data.body as the list of comma separated variables, but can't seem to get it to fire correctly.
My current AHK code is below, the line that attempts to assign tempvar is the one I can't get right.
Settitlematchmode, 2
WinGetTitle, Webstring, Title of the page
wb := IEGet(Webstring)
tempvar := wb.document(data.header[0])
msgbox % tempvar . "|" . Isobject(tempvar)
IEGet(Name:="") {
IfEqual, Name,, WinGetTitle, Name, ahk_class IEFrame
Name := ( Name="New Tab - Windows Internet Explorer" ) ? "about:Tabs"
: RegExReplace( Name, " - (Windows|Microsoft) Internet Explorer" )
For wb in ComObjCreate( "Shell.Application" ).Windows
If ( wb.LocationName = Name ) && InStr( wb.FullName, "iexplore.exe" )
Return wb
}
#vasili111 was on the right track. Try this:
Settitlematchmode, 2
WinGetTitle, Webstring, Title of the page
wb := IEGet(Webstring)
IID := "{332C4427-26CB-11D0-B483-00C04FD90119}" ; IID_IHTMLWindow2
window := ComObj(9,ComObjQuery(wb,IID,IID),1)
tempvar := window.data.header.0
; or use
;tempvar := window.eval("data.header[0]")
msgbox % tempvar . "|" . Isobject(tempvar)
IEGet(Name:="") {
IfEqual, Name,, WinGetTitle, Name, ahk_class IEFrame
Name := ( Name="New Tab - Windows Internet Explorer" ) ? "about:Tabs"
: RegExReplace( Name, " - (Windows|Microsoft) Internet Explorer" )
For wb in ComObjCreate( "Shell.Application" ).Windows
If ( wb.LocationName = Name ) && InStr( wb.FullName, "iexplore.exe" )
Return wb
}

Jquery auto complete feature in combo box with unique values

I'm using Jquery ui autocomplete plugin in a combo box and I'm reading the values from a JSON file. The problem is in my JSON file. I have fields with same value. Like this.
({
name:a
},
{
name:a
},
{
name:b
})
So when I type 'a' in combo box, it gives me 2 'a' s. But I need only one (I need only the unique values from JSON file). How do I do this? I do not have the complete code right now, that's why I cant put it. Sorry about that and thank you.
EDIT: You could use something like this to remove duplicate entries from the json array before sending that data to the jQuery autocomplete plugin.
var names = {};
var param = "name"
$.each(data.people, function() {
if (!names[this[param]])
names[this[param]] = [];
names[this[param]].push(this);
});
Then we can do source: names
try this.... only unique values can be added in input field
select: function( event, ui ) {
var terms = split( this.value );
// remove the current input
terms.pop();
// add the selected item
if(!($.inArray(ui.item.value,terms) > -1))
terms.push( ui.item.value );
// add placeholder to get the comma-and-space at the end
terms.push( "" );
this.value = terms.join( ", " );
return false;
}

How to put the logged in users username in the URL using javascript?

Done alot of research, and haven't found anything helpful yet!.
My question is I would like to put the logged in users nickname in the URL using javascript?
EXAMPLE :
<a href="http://chat.mibbit.com/?server=irc.mibbit.net&channel=%23yourCh&nick=LOGGEDINUSERNICK" target="_blank">open a Chat window
I'll keep looking around. Can anyone help?
I'm assuming you have users nickname defined somewhere. There are two cases: the href is already filled in and you just want to add the nickname, or you are creating the uri + nickname yourself.
Demo: http://jsfiddle.net/ThinkingStiff/4FwHY/
HTML:
<a id="chat" href="http://chat.mibbit.com/?server=irc.mibbit.net&channel=%23yourCh&nick=" target="_blank">open a Chat window</a>
Script (your function in comments modified):
function toggle_visibility( id ) {
var url = 'http://widget.mibbit.com/?settings=46780594e96e435ff18e44e48b7d880d&ser‌ver=irc.Mibbit.Net&channel=%23yourCh&nick=',
username = document.getElementsByClassName( 'user-nickname' )[0].innerText;
document.getElementById( 'chat' ).setAttribute( 'href', url + username );
var e = document.getElementById( id );
if( e.style.visibility == 'hidden' ) {
e.style.visibility = 'visible';
} else {
e.style.visibility = 'hidden';
};
};
When focus leaves the input box, the url gets updated. So they could type their username, then click the link and it will work.

Categories

Resources