Html onclick firing twice in Android - android

Code:
function hello(){alert("Hi");};
<center>
<table border="0" height="100%">
<tbody>
<tr>
<td align="center" width="100%">
<img src="cover.png"
width="300" height="300" id="image"></img></td>
</tr>
<tr>
<td height="100%"> </td>
</tr>
<tr>
<td align="center">
<form onsubmit="go();return false">
<input class="answer" id="answer" name="answer"
onclick="hello();"/>
</form>
</td>
</tr>
<tr>
</tr>
</tbody>
</table>
</center>
I have been trying to capture when the answer text box is clicked in HTML. It works perfectly in Firefox and Chrome (I only get one Hi alert), but the onclick method fires twice when I try to run the code in a web-view in android (I get two Hi alerts). However, when I call the same function later it works properly, firing only one Hi alert.
<div style="bottom: 0; right: 0; position:absolute; margin-right:5%">
<a><img alt="" src="start.png" id="submit" onclick="go();hello();"></a>
</div>
I'm guessing it has something to do with the fact that I'm calling the function from inside the form and it's somehow firing the event twice but I have no idea how to fix it. Any help?

You could try using one() as follows.
$('#answer').one('click', function() {
alert("Hi");
});
<form onsubmit="go();return false">
<input class="answer" id="answer" name="answer"/>
</form>

Related

Form does not send data to e-mail

I'm trying to send the data of this form to my e-mail, but nothing happens. How can I fix it? I'm new at this programming language and I would love some guidance!
<title>Solicitud de Vendedor Honorario</title>
<form action="mailto:erocha#newenergypr.com" method="post">
<table>
<tr><td colspan="2" align="center" bgcolor="#FF8000"><h2>Solicitud de Vendedor Honorario</h2></td></tr>
<tr><td colspan="2" align="center" bgcolor="#D4D4D4">Adiestramiento</td></tr>
<tr>
<td colspan="2" align="center" bgcolor="#1B4F72">
<select name="yesno" id="yesno" size="1">
<option value="yes">Yes</option>
<option value="no">No</option>
</select>
</td>
</tr>
<tr><td bgcolor="#D4D4D4">Nombre:</td>
<td><input type="text" id="nombre" size="14"></td></tr>
...
<tr><td colspan="3" align="center" bgcolor="#FF8000"><h2>Disponibilidad de tiempo</h2></td></tr>
<tr><td align="center" bgcolor="#D4D4D4"><b>Domingo</b></td>
<td bgcolor="#D4D4D4"><b>Desde:</b><select id="domingodesde" size="1">
<option value="0">No disponible</option>
<option value="00">00:00am</option>
<option value="01">01:00am</option>
<option value="02">02:00am</option>
...
More of those, exactly the same but for the other weekdays... Now checkboxes:
<tr>
<td align="center" bgcolor="#F1C40F"><b>Ponce</b></td>
<td bgcolor="#D4D4D4">
<input type="checkbox" id="arr" value="arroyo">Arroyo<br>
<input type="checkbox" id="coa" value="coamo">Coamo<br>
<tr><td colspan="2" align="center"><input type="submit" value="Submit"></td></tr>
The app looks like this:
http://imgur.com/2hiUPKw
http://imgur.com/LEEjryD
Once submited, all the data that was selected should be sent to an e-mail.
EDIT: I see now that the info you are trying to receive is from a webview. If so you can retrieve the info from your webview as such. Found here. After which you will have to parse content from the string.
webView.evaluateJavascript("(function(){return window.document.body.outerHTML})();",
new ValueCallback<String>() {
#Override
public void onReceiveValue(String html) {
}
});

How to login by filling a form in a website using Android

I'm trying to log on to a website that has a form to which you should provide user-name and password, check a box, and press a login button. I tried all kinds of httpClient POST messages, but it seems that it is not working. Can anyone assist and point to an example of skeleton of android Java way to login? Here is the form from the html page:
<form name="loginForm" method="post" action="/login.do">
<table border="0" cellspacing="0" cellpadding="0">
<tr>
<td width="10px"> </td>
<td><label class="formLabel" for="loginID">Username</label></td>
</tr>
<tr>
<td> </td>
<td><input type="text" name="username" value="" class="formTextField"></td>
</tr>
<tr>
<td> </td>
<td><label class="formLabel" for="password"> Password</label></td>
</tr>
<tr>
<td> </td>
<td><input type="password" name="password" value="" class="formTextField"></td>
</tr>
<tr>
<td> </td>
<td> </td>
</tr>
<tr>
<td> </td>
<td><input type="checkbox" name="agreement" value="on" class="formTextField">
I agree with <div>
<b>Terms and Conditions</b></div>
</td>
</tr>
</table>
<p><input type="submit" value="Login" class="FPFormFieldB"></p>
<p>Have you forgotten the password?</p>
<p>New user registration</p>
</form>
I managed to login using JSOUP.
The key is that you need to do a get first, then a post, with the cokies (that includes SessionID and other stuff).
Here is the code that worked for me, hopefully it will assist others:
import android.provider.DocumentsContract;
import org.jsoup.Jsoup;
import org.jsoup.Connection;
import org.jsoup.nodes.Document;
import org.jsoup.select.Elements;
public class Webbing {
public static void Open() throws Exception {
Connection.Response loginForm = Jsoup.connect("http://your website")
.method(Connection.Method.GET)
.execute();
Document document = Jsoup.connect("http://your website")
.data("username", "XXX")
.data("password", "YYY")
.data("agreement", "on")
.timeout(5000)
.cookies(loginForm.cookies())
.post();
String url = "http://a page you want to load after login";
Document fpl = Jsoup.connect(url)
.timeout(5000)
.cookies(loginForm.cookies())
.get();
body = fpl.body().toString();
ExtFile.write(body);
}
}

input type image/* with capture will work in browser but not inside my mobile application

I'm developing a mobile application using phonegap. I have a feature in one of the pages that allows a user to upload or take an image. I'm using input type image/* with capture and it works fine if you open the page on the phone through a web browser but once opened inside the application, it turns into file browser and doesn't allow for camera to take a new photo.
Anyone got any ideas what the problem is?
<table border="0" cellpadding="3" cellspacing="1">
<form enctype="multipart/form-data" action="mob_create.php" method="post">
<tr>
<td width="150">Date:</td></tr><tr>
<td><input type="date" name="inputDate" value="" /> </td>
</tr>
<tr>
<td>Entry:</td></tr><tr>
<td width="300"><input size="34" type="text" name="inputEntry" value="" /></td>
</tr>
<tr>
<td width="150">Add an image (Optional):</td></tr><tr>
<td><input type="file" name="inputPic" accept="image/*" capture ></td></tr>
<tr>
<td><input type="submit" name="submit" /></td>
</tr>
</form>
input type file does not work with androids webview (it works on ios). to get images / videos you have to use the Camera Plugin

Dont show result in form

I have this code in HTML5 using jquery. Fails when trying to run it on Android, don't show the result. Please helpme.
I try to use jquery mobile.
When I run it on my PC runs fine.
<script type="text/javascript" src="js/libs/jquery-1.9.0/jquery.min.js" ></script>
<script type="text/javascript" src="js/libs/jquery-mobile-1.2.0/jquery.mobile.min.js" ></script>
<script type="text/javascript">
$(document).ready(function(){
$("#calcular").click(function(Event){
var v1 = $("#v1").val();
var v2 = $("#v2").val();
var resultado = parseInt(v1) + parseInt(v2);
$("#r").val(function(){
return resultado;
});
return false;
});
});
</script>
</head>
<body>
<div>
<form name="formsuma" id="suma">
<table align="center">
<tr>
<td><label>Valor 1: </label></td>
<td><input name="valor1" id="v1" type="number" /></td>
</tr>
<tr>
<td><label>Valor 2: </label></td>
<td><input name="valor2" id="v2" type="number" /></td>
</tr>
<tr>
<td><label>Resultado: </label></td>
<td><output form="formsuma" name="resultado" id="r"></output></td>
</tr>
<tr>
<td></td>
<td><input type="submit" id="calcular" value="Calcular" /></td>
</tr>
</table>
</form>

where put html form in Res folder and how to show this html form in webview

I have html form.but i dont understand where is put this html form. how to display form in web view.Thanks in advance
<Html>
<Head>
<Title>
<Title>
</head>
<body>
<table width="60%" align="center">
<TR><TD colspan="2"><span class="style1">Post comments</span></TD>
</TR>
<form action="http://www.indianexpress.com/ajax/saveComment.php" id="frmcommentmain" name="frmcommentmain" method="post">
<input type="hidden" value="918703" name="storyId">
<input type="hidden" value="172.16.24.10" name="ip_addr">
<input type="hidden" value="0" name="parentcmtId">
<TR><TD height="35">Name:</TD><TD><input type="text" name="name" tiptitle="Please enter your name">
*</TD>
</TR>
<TR><TD>Email:</TD><TD><input type="text" name="email" tiptitle="Please enter your email">
*</TD>
</TR>
<TR><TD>Title:</TD><TD><input type="text" name="subject" tiptitle="Please enter subject">
*</TD>
</TR>
<TR><TD>Comment:</TD><TD><textarea title="Please enter your comments" rows="6" name="comment"></textarea>
*</TD>
</TR>
<TR><TD colspan="2"><input type="checkbox" value="checkbox" name="checkbox">I agree to the terms of use.</TD></TR>
<TR>
<TD colspan="2"> </TD>
</TR>
<TR>
<TD colspan="2"> </TD>
</TR>
<TR><TD colspan="2"><input type="Submit" name="submit" value="submit"></TD></TR>
</form>
</table>
</body>
</html>
I have read many articles but I did not get answer for putting html form.Many articles described load data from url in webview but i want to load form in webview.
Indeed place your html page in the assets folder.
For showing the webpage use a WebView
WebView wv = (WebView)findViewById(R.id.webview);
wv.loadUrl("file:///android_asset/index.html");
I would store the HTML content in a file in the assets folder in your Android project. You should then be able to read the file from your code and load it into a Webview.

Categories

Resources