My app aims to make a golf booking via a booking page on my golf club website. I have so far programmed the log in and loaded the required booking page (into a webview) which has rows of time slots for 4 players. The html source for each row is something like:
When the user clicks on the Book Now button a further page is loaded in which he selected the player names. Should I be able to use WebViewExtras1.executeJavascript with a suitable javascript (which I'm not very familiar with) to simulate pressing the Book Now button or is there some other way of doing this?
Thanks for the reply. It was the fact that the form did not have a name (unlike the one for login) that made me wonder if there was some other way of ding this. Depending on which time slot you want to book the form may not be the first one. Perhaps I could loop through all the forms to get the desired time slot and then use its index in the submit.
Open the website in your browser, inspect the Source and have a look at the javascript function. It must be inside one of the included javascript files...
function ValidateMemberBookNow(form)
{
if (form.SubmitButton.value == "Confirm Booking") {
form.SubmitButton.disabled = true;
form.SubmitButton.value = 'Wait...';
}
if (form.double_click.value == "Yes")
{
alert("Warning: You have clicked the 'Booking' button twice.\nThis will send two requests to the server and result in a slower response.\nFor optimum performance, please press all buttons in the booking system only once.");
return false;
}
form.double_click.value = "Yes";
return true;
}
Triggering form submission from JavaScript will ignore the onSubmit function. So you have to simulate a submit button click instead of submitting the form directly.
B4X:
Dim js As StringBuilder
js.Initialize
js.Append("document.forms[11].double_click.value = '1';")
js.Append("document.forms[11].course_id.value='3';")
js.Append("document.forms[11].d_date.value='2019-03-06';")
js.Append("document.forms[11].Teetime.value='15:00';")
js.Append("document.forms.[11].SubmitButton.click()")
WebViewExtras1.executeJavascript(WebView1, js)
there's no rocket science happening in the function called by the onsubmit so it should work the submit() way aswell if implemented correctly.
(for example his time & date lack quotes which will brake the JS code already)
it's better to parse pages and use your own display & post methods instead of using this webview hackering imho.
I really wouldn't know how to do that so thought the existing form submission approach would be easier. A simple example of your suggestion would help!
the ideas is to drop the webview and read in the website page and then parse the data with regex filters or other methods.
then you build up the post data and send it back to the server.
if you plan an IOS release you can forget about the way you do it now as it won't pass the review team.
for now I guess you better stick to what you already have.
if you can wrap up the project and PM a link to it I'll have a look at where it goes wrong.