Let's say I have a form:
<form id = "form1" action = "process.php" method = "post">
...
</form>
Now, submitting it from JavaScript using link would look like this:
<a href='javascript:document.forms["form1"].submit()'>Submit</a>
How do I do the same with Dart-lang?
I don't think you can use inline dart script inside href
attribute of <a>
.
However, you can add a onClick handler on your anchor :
import 'dart:html';
main() {
AnchorElement a = query("#a1");
a.on.click.add((e){
FormElement form = query("#form1");
form.submit();
// stop event
e.preventDefault();
e.stopPropagation();
});
}
And your anchor can look like :
<a id="a1">Submit</a>
If you need to retain the hand cursor (because it's now gone after taking the useless href
) or style it otherwise, just use CSS:
a {
cursor: pointer;
color: #00f;
text-decoration: underline;
}
a:hover {
text-decoration: none;
}
Alexandre Ardhuin gived you a good head start, but you have to use a <input type="submit" value="Submit">
to allow the user the use the enter key on their mobile device or on their keyboard:
<form>
<input type="submit" value="Submit">
</form>
And dart code:
main() {
Element form = query("form");
form.on.submit.add((e){
// Do your stuff here...
// Stop event
e.preventDefault();
e.stopPropagation();
return false;
});
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With