Excel VBA - Manipulate Javascript - javascript

I have researched stackoverflow and other sources for many weeks for an answer to this question but have not been able to uncover an answer. I appreciate that there may be other posts that indirectly deal with the topic, but nothing seems to address the requirements of the specific example I have in mind, so I'm taking the plunge and posting. My request:
On the website www.4-traders.com there's an input box located at the top center of the page for entering a company name or stock ticker symbol. The page contains code that calls a javascript function as one types into the input box. The javascript searches a database for the best matches to the text being input, and the output of the javascript function is presented as a floating list box that one can select from. The code for this component of the page is as follows:
<td class="recherche_bl">
<input type="hidden" name="lien" value="recherche">
<input onblur="GlobalSearch.ACblur();" onkeyup="GlobalSearch.ACkeyUp(event)" onkeydown="return GlobalSearch.ACkeyDown(event);" autocomplete="off" type="text" name="mots" id="autocomplete" class="inputrecherche" value="Symbol or Keyword(s)" onclick="document.recherche_menu.mots.value='';GlobalSearch.LoadHisto()">
<input type="image" src="/images/loupe_recherche.png" class="htZo" align="absmiddle" onclick="document.getElementById('noredirect').value='1'">
<input type="hidden" name="RewriteLast" value="zbat">
<input type="hidden" id="noredirect" name="noredirect" value="0">
<input type="hidden" id="type_recherche" name="type_recherche" value="0">
</td>
GlobalSearch is the javascript function I'm interested in. I'd like to get Excel VBA to somehow select from the output of the GlobalSearch function after a value is input into the form. I currently have to use sendkeys to accomplish this, which as everyone knows has a number of drawbacks and requires that an Internet Explorer windows is open at the time. Here is the code I'm currently using for this piece:
The value of Ticker is set before this part of the code.
.document refers to an Internetexplorer.Application object I have created earlier on in the code.
PauseTime is a procedure used to delay the execution of code.
The two lines involving sending a 'space' and 'backspace' key are used to get the javascript to run (it doesn't seem to run without some manual user input). Once the javascript runs I want the procedure to select the first instance in the list box, so I send a 'down' key and then an 'enter' key.
.document.recherche_menu.mots.Focus
.document.forms("recherche_menu")("mots").Value = Ticker
PauseTime (2)
Application.SendKeys (" ")
Application.SendKeys ("{BS}")
PauseTime (2)
Application.SendKeys ("{DOWN}")
Application.SendKeys ("~")
I would really appreciate some help to figure this out. I think the real issue is that I don't have a deep enough understanding of javascript to code what I need to into Excel VBA. Thanks in advance for your help.
Constantine

Related

[Javascript]Fill a textbox without ID and a name that changes on page reload using a bookmark

So I am trying to make a bookmark in chrome that would input a Javascript code that would fill up a textbox on my router home page. The goal is saving me the hassle of either remembering that silly password or having to open my textfile containing the said password.
I know, I know, ... I am lazy. (but not for learning some Javascript in the process)
The thing is the textbox doesn't have an ID and its name changes on reload so I cannot know its name in advance.
I have looked at a few pages on here that kind of guide me in the right direction but I can not make it work for the life of me as I have little to no experience in Javascript.
Here is what the html of the textbox looks like :
<input type="PASSWORD" style="WIDTH: 150px" name="password_random10digitnumber" value="" size="20" maxlength="64">
Here is what I ended up with as a link on my bookmark (the only thing I tried that doesn't give me an error).
javascript:document.getElementsByTagName("input")[0].value='myrouterpwd'
Currently, when I press my bookmark, it refreshes the page and shows a blank page with "myrouterpwd" on it.
(There is two other input html blocks on the page which are :
<input type="HIDDEN" name="md5_pass" value="">
<input type="HIDDEN" name="auth_key" value="numbersIamnotsureIshouldshowtheworld">
)
Thank you to anybody taking the time to answer!
I haven't worked much with bookmarks and am assuming that because it's a bookmark, you are navigating away from the page that you actually want to work with. So, I'm not sure that triggering this that way is a viable solution. Of course, you could just take advantage of the browser's ability to store passwords for you. ;)
But, to the main point of your question... Assuming that it's the only password field on the page, the use of element.querySelector() will find it:
// Get a reference to the right element based on its type attribute value
let passwordBox = document.querySelector("input[type='password']");
passwordBox.value = "MySecretPassword"; // Populate the field
console.log(passwordBox.value); // Confirmation
[type='password'] { background:yellow; } /* Just so you know which box is the password box */
<input type="hidden" name="doesntMatter">
<input name="someTextBox">
<input type="password" name="doesntMatter2">
<input name="someOtherTextbox">

how to fill the timestamp by input something in the textfield manually?

I am not a web developer. So my question maybe a bit silly.
The scenario is quite simple: there are two text fields for user to input username and email address and one button to click to send the inputs to the server.
Normally there is nothing special, but i check the datagram send to the server by using google chrome's developer tools, and i find there is actually three items: name,email,timestamp. And timestamp is an empty string. Then how can i fill these 3 items by only 2 textfields and also don't know the code?
The server side is a black box. I think what i can do is input somethings to these 2 textfields and click the button. I wonder can i just add something in the second text field to fill the email and the timestamp field together? Or any other techniques i can use?
Any suggestions are appreciated.
P.S.
1.This is just an interesting test. i want to try it out. If success, there should be something come out when click the button. But when i click there is nothing but a warning to let me try to see the datagram. when i check the datagram, i see there is one timestamp which is empty. i guess i should try to fill the timestamp to make it.
2.The request method is POST. Status Code:200 OK
Request Payload {name:XXX,email:XXXXXX,timestamp:}
email:"XXXXXX"
name:"XXX"
timestamp:""
3. The form code is as follows:(i copy by viewing source of the page)
<form class="mt30" id="msgForm">
<input type="text" name="name" placeholder="name" />
<input type="text" name="email" placeholder="email" />
<input type="hidden" name="timestamp" />
<div class="mt30"><button class="btn" id="btnSubmit">open</button></div>
</form>
The following returns the number of milliseconds since the epoch in Js
time_stamp = new Date().getTime();
Just Send It With The Post fileds.
If So And don't No If I Should answer This But :
Go To This Site epochconverter And Copy The current Unix epoch time And Place It In The TextFiled

Javascript glitch breaking a POST function for select input

thanks for taking a moment to look at my question.
I have a requirement to create a data collection method that is done in three phases. Final data is to be stored in a MySQL database.
1st - Personal details (this part is easy and has been completed)
2nd - Expense details (this part is the part that is my headache)
3rd - Receipt scan upload (this part is also relatively easy and has been completed also).
Technologies in use - html, php5, javascript, mysql, running on a standard LAMP stack.
Personal limitation - me. Not very fluent in php and have not used it in a few years.
1st screen works perfectly.
3rd screen works perfectly but requires completion to email the user upon finalisation of completing the process. Not a problem as I have done this before.
2nd screen has two tables, each with a small variety of input fields. The first of these tables is using JavaScript to clone table rows so that the user can propagate as many of these rows as they need. Each row is comprised of the following fields:
<input class="mus3" type="text" name="reg_travel_date1" id="reg_travel_date1" maxlength="20"><br><input type="button" name="button2" id="button2" value="+1 row" class="button" style="width: 80px; margin-top: 18px;">
<textarea class="mus1" name="reg_travel_from1" id="reg_travel_from1" cols="10" rows="5"></textarea>
<textarea class="mus2" name="reg_travel_to1" id="reg_travel_to1" cols="10" rows="5"></textarea>
<input class="mus4" type="text" name="reg_kms_travelled1" id="reg_kms_travelled1" maxlength="10" onkeydown="validateNumber(event);">
<select class="select" style="width: 120px;" name="exp_type_car_travel1">
<option selected>Type...</option>
<option value="Seminar">Seminar</option>
<option value="Rural Travel">Rural Travel</option>
<option value="Conference">Conference</option>
<option value="Exam">Exam</option>
<option value="Other">Other</option>
</select>
<input type="text" name="reg_claimable_kms1" id="reg_claimable_kms1" maxlength="10" class="mus5" onkeydown="validateNumber(event);">
To see further detail, I have posted ALL of the code used at the following links (there is not enough space in here).
I have had to double up on my linked code as I am only permitted to post two links, it appears.
index.php FOLLOWED BY C.claim2.php : http://pastebin.com/wufh4Q47
css_file.css FOLLOWED BY C.claim.php (complete and working) : http://pastebin.com/iGnEsTC3
The jquery.min.js file is version jQuery v2.0.3
I've pasted the code for the first screen which is working fine, as an indication of the hoped for behaviour of the second screen.
PROBLEM:
I am trying to make it so that the select field in the JS clone function will increment it's name/id like the text and textbox fields do (or did before this particular version, for some reason). It has always cloned itself with the exact same name as the starting row which has caused serious problems in the resulting post function.
Also, for some reason that may or may not be related, the select field always posts a blank value, regardless of how many cloned rows there are. I do not know why, nor how to fix this.
Can anyone help? I am not skilled in JS at all, the JS used on this project was written for me by a friend who is also wondering why it's not quite working as desired.
Thank you. :)
Ok, ignore this question now - the situation has been resolved fully and is working perfectly. It appears there is a bug in JQuery that has been chosen as to be "not to be fixed" as the overheads to do so are too high. This problem results in the choices to be blank, their 'name="something"' values being dropped. We have a work around now and the function now performs perfectly, thanks to my friend. Much appreciation Crystal!

Display text "loading..." after file is selected in input type="file" element

I am using a really simple form to allow users to upload files to my server. It works well, but i have noticed that even for very small files, right after selecting the file to upload, it takes a while (2-3 sec) to change the "No file selected" to the actual name of the file selected. (Actually it says it in spanish - guess somebody knows where i am).
The thing is that during this loading time the mouse wheel nor the browser look like they are thinking, so im afraid the user wont be patient enough and will feel its not working.
So i just want to display a text saying, "hey, hold on - its loading" And this is what i have tried with no luck:
A.
<input type="file" name="userf" onload="function(e){e.innerHTML='Loading';};">
</input>
B.
<input type="file" name="userf" onchange="function(e){e.innerHTML='Loading';};">
</input>
C.
<input type="file" name="userf" onload="function(){this.innerHTML='Loading';};">
</input>
D.
<input type="file" name="userf" onchange="function(){this.innerHTML='Loading';}">
</input>
If this is not possible, could i not just change the default message: "No file selected"?
EDIT
If possible, no JQuery, just javascript
You cannot change the default text on an input file element. But you can do some work arounds in order to get something similar you want. It may require jQuery or other framework to do the job.
This post may help: How to change the button text of <input type="file" />?

Javascript - concatenate field value to onclick button link?

I have an issue I need to fix on an existing app that I didn't initially write. Here is a snippet of code that doesn't do what it is intended to do. What it is supposed to do is take the value of the field and upon clicking "Search", append that to the redirection to pass in the querystring to the destination page:
<form name="frm_someform">
<input type="text" name="f_date" id="f_date"/>
<input type="button" value="Search" onclick="parent.location='runreport.asp?date=' + document.frm_someform.elements['f_date'].value); + '"/>
</form>
Now, as you javascript folks can plainly see, the concatenation doesn't work. I've searched high and low for how to properly concatenate, but something isn't translating correctly (in my head). Note that if I take out the concatenation, the redirection works fine, so there is something with that causing the issue. Yes, of course in the example above, I could simply make the form submit the proper value with a real 'submit' button, but I have whittled the code down here for simplicity - it is much more complex than the example I have above.
(*Note, I successfully tested concatenation through other javascript functions, but the possibility exists that the purely inline code must be different)
Thanks in advance,
Beems
Please, try this:
<form name="frm_someform">
<input type="text" name="f_date" id="f_date"/>
<input type="button" value="Search" onclick="parent.location='runreport.asp?date='+ document.getElementById('f_date').value"/>
</form>

Categories