0

I have a html source code which has a text box and upon typing in it and on clicking the submit button gives you the input text (like a to-do list). I want that text along with a checkbox.

Nakilon
  • 34,866
  • 14
  • 107
  • 142
Santosh459
  • 23
  • 2
  • 2
  • 6
  • Yes, that can almost certainly be done, but it's very unclear from your question what "that" is. Please include code and be more specific. What do you mean by "gives you the input text"? What do you mean by "I want a that text"? – foobarbecue Oct 24 '13 at 19:48
  • delete checkbox Add Events – Santosh459 Oct 24 '13 at 20:39

3 Answers3

1

Is this what you saying about, try the demo,

jsfiddle demo

html

<div id="check">
    <input type="text" class="txt" value="" />
    <button type="button" class="btn">Click Me!</button>
</div>

jquery

$(document).ready(function () {
    $(".btn").on('click', function () {
        $('#check').append('<input type="checkbox" name="myCheckbox" />' + $(".txt").val());
    });
});
Sobin Augustine
  • 3,639
  • 2
  • 25
  • 43
  • Hi Sobin,It worked well thank you,is there anyway to have a delete button as well??my exact requirement is that i need an upload file event where the file is selected from the upload file pop-up along with the checkbox which we have created using the above code. – Santosh459 Oct 28 '13 at 05:58
0

https://developer.mozilla.org/en-US/docs/XUL/checkbox

<checkbox label="Your checkbox" checked="true"/>
jonosma
  • 339
  • 1
  • 4
  • if he's using XHTML it should be `checked="checked"`, if he's using HTML5 just `checked`. but `true` is a really bad idea. people might think `checked="false"` would do the opposite. – ThiefMaster Oct 24 '13 at 20:21
0

DEMO: jsFiddle


Description: This uses pure JavaScript and not jQuery as you didn't specify jQuery.


HTML

<form onsubmit="test(event)" action="POST">
    <label for="textbox-1">Textbox: </label>
    <input type="text" id="textbox-1" />
    <label for="checkbox-1">Checkbox: </label>
    <input type="checkbox" id="checkbox-1"/>
    <input type="submit"/>
</form>

JS

function test(event){
    event.preventDefault();
    var textbox1 = document.getElementById('textbox-1').value;
    var checkbox1 = document.getElementById('checkbox-1').checked;
    alert("Textbox value: " + textbox1 + " || checkbox: " + checkbox1);

}

Note: In the JavaScript you will simply post this to a back-end you don't need to event.preventDefault nor the variable getting. However, this code can be used for an AJAX submit.

abc123
  • 17,855
  • 7
  • 52
  • 82
  • -1, only works in IE. there is no global `event` in any other browser. you probably meant `onsubmit="test(event);"` – ThiefMaster Oct 24 '13 at 20:19
  • @ThiefMaster i did! :) woops thanks, event.preventDefault also works in Chrome (just tested in) and Mozilla according to their documentation page? – abc123 Oct 24 '13 at 20:22
  • Yes, those functions are standardized. [I wouldn't expect them to work in oldIE though.](http://stackoverflow.com/questions/1000597/event-preventdefault-function-not-working-in-ie) – ThiefMaster Oct 24 '13 at 20:25