Is there a way to label the Go button in iPhone Safari? - iphone

When focus is placed into an input of this form, iPhone shows input keyboard and Go button, which acts as submit. Is it possible to change the label to e.g. "Create"? I tried value, title or name but none of those work.
<form>
<input name="foo" type="text"/>
<input type="submit" name="Create" value="Create" title="Create"/>
</form>

No, something like this is not possible.

Related

Submit on enter with 2 text inputs

I have two text inputs and each has a submit button. Each button has an on click AJAX function that calls a php script and populates the page.
I need to find a way to make the enter key submit the button of the input text focused.
For example if I type something the in the "product_code" input text and press the Enter key I want to call the AJAX function of that input's assigned button (getByCode()).
Product name: <input type="text" name="product_name" id="product_name">
<input type="submit" value="Search" onClick="searchByName(document.getElementById('product_name').value)"> <br />
Product code: <input type="text" name="product_code" id="product_code">
<input type="submit" value="Search" onClick="getByCode(document.getElementById('product_code').value)"> <br />
I don't necessarily require input buttons, I could use images for example if that helps.
All browsers support document.activeElement which will tell you which element has focus. On your keypress event handler, check this value against your two inputs to see which has focus. If neither has focus, then ... ?

How to detect which submit button was clicked when the names are unknown?

I know how to detect which submit button was clicked when I know the name values of each of the buttons. But what if the names are dynamic or defined by another component?
For example, here I can simply check the POST data from this <form> for either alpha or bravo:
<form>
<input type="submit" name="alpha" value="Alpha">
<input type="submit" name="bravo" value="Bravo">
</form>
But that's only because I know I should be looking for those names.
Is there a best practice for handling this type of situation? (Perhaps by rendering an element <input type="hidden" name="submit-button-names" value="dynamic_name1|dynamic_name2|etc">.) I would like a solution that doesn't require JavaScript.
Presuming you have control over the JSP displaying these buttons, just prefix the button names with a string you can look for in the POSTed data. For example prepending "dynamicbutton_" to all of the names like this
<form>
<input type="submit" name="dynamicbutton_alpha" value="Alpha">
<input type="submit" name="dynamicbutton_bravo" value="Bravo">
</form>
Then in your Servlet, look for values with this prefix by calling ServletRequest.getAttributeNames()
You could write a custom tag to set the different inputs to your form based on a list of parameters you give to the tag.
You would end up with the HTML looking something like this:
<form method="POST" action="SelectColour.do">
<p>Select your favorite colour: </p>
<formTags:select name='colour' size='1' optionsList='${applicationScope.colourList}'/>
<input type="SUBMIT" value="Click here to submit">
</form>
Here's a decent guide to creating custom tags.

Binding multiple text boxes with multiple submitt buttons in same form

I have a form where I have a search functionality with a text box(TextBox1) and a submitt button(Button1). Apart from search, there is another set of textbox(TextBox2) and submitt button(Button2). When I write something in search box(TextBox1), and hit enter, the validation message of the second textbox(TextBox2) is shown.
I am not sure how to bind the respective textboxes with submitt buttons. Please help.
Thanks in advance
Depending on how much control you have, the easiest way would be to have separate forms for each texbox/button combo.
<form action="dosomething.php">
<input type="text" name="foo" />
<input type="submit" />
</form>
<form action="dosomethingelse.php">
<input type="text" name="bar" />
<input type="submit" />
</form>
If you can't or don't want to do that, you'll need to look at handling the onkeydown event on the text boxes to prevent an automatic submission. Something like <input type="Text" name="foo" onkeydown="doSubmit(this); return false;" />. Note the return false;, which prevents the default action from taking place.

Why does enter submit a form differently than clicking submit in IE 7?

In IE 7 the zip code search form on my page reacts differently when someone clicks submit vs pressing enter. It works correctly when sumbmit is clicked and incorrectly when enter is pressed.
http://getridofit.com
<form name="zip" action="<?php bloginfo('url'); ?>" method="get">
<input type="text" id="zipper" name="locations" size="5" maxlength="5" class="junk-input" onsubmit="return checkForm()" />
<input type="submit" value="" name="schedule" src="/wp-content/uploads/remove-my-junk.png" align="center" class="junk-button" style="background: #f67a3e url(/wp-content/uploads/remove-my-junk.png); border: none; width: 201px; height: 45px;"/>
</form>
The correct result for a zip search of 85718 looks like this: http://getridofit.com/l/85718/?schedule
but pressing enter produces a result like this: http://getridofit.com/l/85718/
Because the button wasnt clicked in order to submit the form. If you dont click the button then the input for #name[schedule] isnt sent. However if that button input has focus when enter is pressed i think it will send it along properly... You might jsut want to make schedule a hidden input.
It looks like you are checking for the presence of the submit button variable (schedule) in the URL bar. The submit button variable is only supposed to be submitted when the user physically clicks the the submit button. However, I can't reproduce the problem in Safari, so it may also depend on what your JavaScript is doing when the form is submitted.

Disable predictive text on iPhone for a form field

Is there an attribute which I can specify for an <input> element which would turn off the predictive text functionality for this given field?
Something along the lines
<input type="text" predictive="disabled" />
There are some options:
<input type="text" autocomplete="off" autocorrect="off" autocapitalize="off">
On a per form field basis you can always do the following:
<input type="text" autocorrect="off" />
From the user side you can
Settings > General > Keyboard >
Auto-Correction On/Off.
from the app side, i don't think it can be done.