0

I am trying to make an input text to have a title option, like you can make with the div's...It is possible to do this?

This is what I've tried, but it seems that it doesn't work... HTML:

<label>
   <input type="checkbox" class="promote_checkbox">Promote with</input>
   <input type="text" class="promote_points_number" maxLength="3" title="you need minimum 5 points to promote">Points</input>
</label>

And I also have another problem with this label: if you're trying to type something in the textbox you can't because the checkbox will be checked...can you please tell me why is this thing happening?

http://jsfiddle.net/2xw32q80/

Valeriu92
  • 118
  • 1
  • 13
  • 1
    The `title` attribute creates a tooltip in common browsers. If this does not happen when you test it, you need to specify the conditions more exactly so that others can reproduce the issue. Your other problem is a direct consequence of incorrect use of `label` element; you cannot use two `input` elements inside one `label`. On the other hand, you hardly need the checkbox at all. Simply let users enter a promotion code; your form data handler should just check whether the code is empty before otherwise checking it. – Jukka K. Korpela Feb 06 '15 at 13:04

2 Answers2

1

In HTML, the <input> tag has no end tag whereas in XHTML it must be properly closed, like this <input />.

The <label> tag defines a label for an <input> element, so you need to wrap each <input> with their own <label> tags like so:

<label>Label for checkbox
    <input type="checkbox" class="promote_checkbox">
</label>
<label>Label for points
    <input type="text" class="promote_points_number" maxLength="3" title="you need minimum 5 points to promote">
</label>

OR have a for attribute on each <label> that corresponds to the id attribute of its <input>

<label for="box">Label for checkbox</label>
<input type="checkbox" id="box"><br>
<label for="points">Label for points</label>
<input type="text" id="points" maxLength="3" title="you need minimum 5 points to promote">
-1

Watch your markup, you did not close the <input> tags! This works for me in Opera:

<label>
  <input type="checkbox" class="promote_checkbox" />Promote with
  <input type="text" class="promote_points_number" maxLength="3" title="you need minimum 5 points to promote" />Points
</label>

Result:

Text edit with title

jbutler483
  • 24,074
  • 9
  • 92
  • 145
user1438038
  • 5,821
  • 6
  • 60
  • 94
  • What version are you using? Firefox [does support](https://developer.mozilla.org/en-US/docs/Web/Guide/HTML/Forms_in_HTML#Constraint_Validation) using the title tag as tooltip. – user1438038 Feb 06 '15 at 11:24