Submit a method in webbrowser - vb.net

I have a problem invoking a submit method in web page
This is my code
Webbrowser.document.forms(0).invokemember("submit")
It does nothing.
Here is the html
<form name="myWebForm" action="myServerSideScript.php" method="post">
<input type="checkbox" /> Checkbox 1<br />
<input type="text" /> Text Field 1<br />
<input type="submit" value="SUBMIT" />
</form>

You must set .AllowNavigation property to "TRUE"
Webbrowser.AllowNavigation = True
And call submit method like this
Webbrowser.Document.Forms(0).InvokeMember("submit")
Or
Webbrowser.Document.Forms.GetElementsByName("myWebForm").Item(0).InvokeMember("submit")

Related

Clear all input fields on submit using Hyperscript

I'm playing around with htmx and hyperscript, and I want all input fields in the form below to be cleared on submit:
<form hx-post="/example" hx-target="#table tbody" hx-swap="beforeend"
_="<what should I write here??>">
<label class="control-label" for="firstNameInput">First Name</label>
<input id="firstNameInput" name="firstName" class="form-control" type="text" required placeholder="John"/>
<label class="control-label" for="lastNameInput">Last Name</label>
<input id="lastNameInput" name="lastName" class="form-control" type="text" required placeholder="Doe"/>
<button class="btn btn-primary">Add User</button>
</div>
</form>
I've tried replacing <what should I write here??> with e.g. on submit put '' into <input/> and on submit put '' into <input[value]/> and lots of other combinations but I fail to get this work.
Q: How can I clear all input fields when the form is submitted?
Try with on htmx:afterRequest reset() me

NET Core - Submit on input change, not button click

Currently, I have a form that calls a method in my controller. It sends a string as a parameter to my IActionResult (the string is always a numer since I am getting it from an input of type range between 1 and 12). The method looks like this: public IActionResult ChangeForecastMonths(string forecastMonths) The code in my view is the following:
<form asp-action="ChangeForecastMonths">
<input asp-for="FutureForecastMonths" name="forecastMonths" type="range" class="custom-range" min="1" max="12" step="1" />
<input type="submit" value="Save" class="btn btn-primary" />
</form>
What I'm trying to do is -- instead of the ChangeForecastMonths method being called whenever the submit button is clicked -- to actually have it called whenever the input field changes its value.
You could hook to the change() event of the input, then fire a submit() on the parent form, like this:
<form asp-action="ChangeForecastMonths">
<input asp-for="FutureForecastMonths" name="forecastMonths" type="range" class="custom-range" min="1" max="12" step="1" />
<input type="submit" value="Save" class="btn btn-primary" />
</form>
#section Scripts
{
<script>
$('form input').change(function() {
$(this).closest('form').submit();
});
</script>
}
Result:

skip radio buttons when posting the form

I have a rails from inside that I have some radio buttons which I don't want to post in my Edit action.
<form accept-charset="UTF-8" action="/feedbacks/3" id="edit_feedback_3" method="post">
<input id="1_1" name="1" type="radio" value="1" />Yes
<input id="1_1" name="1" type="radio" value="1" />No
<input id="feedback_answers" name="feedback[answers]" size="30" type="text" />
<input name="commit" type="submit" value="Submit" />
</form>
and these radio buttons are not bound to a model's attributes, How can I POST only the 'feedback_answers' to server.
All this is because I'm facing this issue with radio buttons
I'm using ruby 1.9.2 and rails 3.2.6.
A good way to handle this is to disable the radio buttons with javascript on submit:
function disableButtons() {
document.getElementById('1_1').setAttribute('disabled', 'disabled');
return true;
}
Then add the following in the form:
onsubmit="return disableButtons()"

How to render a Zend_Form_Element_MultiCheckbox form an array?

I need to render a MultiCheckbox like below:
Wanted:
<label>
<input type="checkbox" name="privacy[read_only]" value="1" /> Just for read only
</label>
<label>
<input type="checkbox" name="privacy[is_pulic]" value="1" /> Is public
</label>
How can I do that? I just can do with:
Unwanted:
<label>
<input type="checkbox" name="privacy[]" value="read_only" /> Just for read only
</label>
<label>
<input type="checkbox" name="privacy[]" value="is_pulic" /> Is public
</label>
Thanks so much for any your ideas.
If there was nothing else in your form, or you didn't mind each form element having the same format, you could use setElementsBelongTo($array) which is a method on a Zend_Form.
You might also then have to use individual checkboxes to acheive the desired markup, so this may or may not work in your scenario.

How to get Index of the FORM Element in the WebBrowser Control?

let say a site has 2 forms: one search form and the other is a registration form...
<form>
Search: <input type="text" name="s">
<input type="hidden" name="a" value="search">
<input type="submit" value="Search">
</form>
[..]website content blabla[...]
<h2>Registration</h2>
<form>
E-Mail: <input type="text" name="email">
<input type="hidden" name="a" value="reg">
<input type="submit" value="Register">
</form>
If I submit a form, I want to know to which form the clicked submit button belongs. GetElementbyId is not possible because the id is not always available. I want to get the index. Any ideas? (WebBrowser Element in VB.NET or C#)
You cant refer to Form object of Input Element e.g btn.Form.Name should work; give it a try
http://msdn.microsoft.com/en-us/library/aa703812(v=vs.85).aspx (reference to IHTMLInputElement::form Property)