1

I would like to show a form with submit button, to post the texts fields back to server with:

  • a text input called title, with border
  • text called chapter and section no border, and their should be assigned in JavaScript

I want chapter/section not modifiable and short. But Title is a normal input and should be very close to the word Title, like:

Chapter 3 Section 4 
       _____________
Title |_____________|

I wrote CSS like "input[type="notext"]{border: none} then either both text inputs have border, or none has border. I basically want the two inputs to have different style, or some other kind of field for chapter/section for me to set value is fine too. So how to achieve this? Don't need to be compatible for IE8 and before.

input[type="text"]{
border: none;
font-size: 16px;
}
<form action="#" method="post" id="form" >
    <table>
        <tr>
            <td>Chapter<input type="text" value="3" name="cha_n" readonly/></td>
            <td>Section <input type="text" value="4" name="sec"     readonly/></td>
        </tr>
        <tr>
            <td>Title  </td>
            <td><input type="text" style="inputtext" name="title" id="title"/></td>
        </tr>
        <tr>
            <td span='2'><a id="submit" href="javascript: check()">Send</a></td>
        </tr>
    </table>
</form>

4 Answers 4

4

You can define a CSS class for your inputs and just use them.

For inputs with class example:

input.example {
        border: none;
        font-size: 16px;
}

Use it like this:

<input class="example" type="text" value="3" name="cha_n" readonly/>

Example: http://jsfiddle.net/x762v24a/


A less generic way to achieve this is to use CSS attribute selector:

input[name="cha_n"] {
    border: none;
}
Sign up to request clarification or add additional context in comments.

3 Comments

Thanks, so is there a way to minimize the chapter input box to just enough, since the value is a readonly already set?
Yes, there is, but the style can't change dynamically just via CSS, you would have to use script, if that's ok
You can use the size attribute of inputs to adjust their size too if you know what range of values you will be dealing with
1

To remove the borders on the chapter and section inputs, use:

input[readonly] {
  border:none;
}
<form action="#" method="post" id="form" >
    <table>
        <tr>
            <td>Chapter<input type="text" value="3" name="cha_n" readonly/></td>
            <td>Section <input type="text" value="4" name="sec"     readonly/></td>
        </tr>
        <tr>
            <td>Title  </td>
            <td><input type="text" style="inputtext" name="title" id="title"/></td>
        </tr>
        <tr>
            <td span='2'><a id="submit" href="javascript: check()">Send</a></td>
        </tr>
    </table>
</form>

Comments

0

Try to give inputs having the same style an 'class' attribute,then :

.style1
{
    border = 0px solid #FFFFFF;
}
.style2
{
    margin = 0px;
    padding = 0px;
    border = 1px;
}
<form action="#" method="post" id="form" >
<table>
    <tr>
        <td>Chapter<input type="text" value="3" name="cha_n" class="style1" readonly/></td>
        <td>Section <input type="text" value="4" name="sec"  class="style1"   readonly/></td>
    </tr>
    <tr>
        <td>Title  </td>
        <td><input type="text" style="inputtext" class="style2" name="title"id="title"/></td>
    </tr>
    <tr>
        <td span='2'><a id="submit" href="javascript: check()">Send</a></td>
    </tr>
</table>

2 Comments

I put in the fiddle and it didn't work like you said?
Your CSS syntax is invalid.
0
<form action="#" method="post" id="form" >
    <table>
        <tr>
            <td>Chapter<input type="text" value="3" name="cha_n" /></td>
            <td>Section <input type="text" value="4" name="sec" /></td>
        </tr>
        <tr>
            <td>Title</td>
            <td><input type="text" style="border:none;font-size:14px;" name="title"/></td>
        </tr>
        <tr>
            <td span='2'><a id="submit" href="javascript: check()">Send</a></td>
        </tr>
    </table>
</form>

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.