jquery - Create an option menu in javascript -


i making soduko game in html , javascript. want make user select numbers (0 - 9) instead of entering them.

here example 1 input (cell 0:0):

<td><input id="c00" type="text" size="1" onclick="validate()"/></td>

i javascript code display option of 0-9 when cell clicked.

my idea that.

if oncliked() display menu document.getelementbyid("c00").value = selected value. 

you should use classes instead of ids click event, like:

<td><input class="number-select" type="text" id="c00" size="1"/></td> 

then can bind of them in jquery:

$("input.number-select").click(function(){     $("#tile-chooser").show();         ... } 

inside callback can use

$(this).val()  

to or set value of textbox.

also on click should show numbers selector. can creating div data-input-id attribute store id of textbox fill.

then in div can create 10 divs digits on them , special class digit-tile , attach callback them:

$("div.digit-tile").click(function() {     var inputid = $(this).parent().data("input-id");     $("#" + inputid).val($(this).data("value"));     $(this).parent().hide(); } 

your tiles can this

<div id="tile-chooser" style="display:none">     <div class="digit-tile" data-value="1">1</div>     ... </div> 

add css , should work.

last thing need add positioning of div tiles close textbox out of scope of question think.


Comments

Popular posts from this blog

javascript - jquery or ashx not working -

opencv - DataType<cv::detail::deriv_type>::depth what is it used for -

python 3.x - Mapping specific letters onto a list of words -