2011-09-14 2 views
0

As the title says I'm trying to basically added the numbers 0-9 to a text box and also be able to delete the last input number(basically last digit in textbox or decrease length of data by 1 or w/e to produce this).Ghazanfarミール<a onclick and then also delete last value added (values = 0-9)

Like you can see below I've setup basically a keypad of buttons which I'm trying to record the value of each to a specific textbox.

<%: Html.TextBox("TBBlah") %> 

<a onclick="$('#TBBlah').append('7');" class="large button" style="color:Black; text-decoration:none;">7</a> 
    &nbsp; 
    <a onclick="$('#TBBlah').append('8');" class="large button" style="color:Black; text-decoration:none;">8</a> 
    &nbsp; 
    <a onclick="$('#TBBlah').append('9');" class="large button" style="color:Black; text-decoration:none;">9</a> 

I'm trying to set this up in this precise way to allow users to enter a code via a touchscreen.

With the code above it says Object doesn't support this property or method which has me wondering what I did wrong.

also was wondering in case this would help (these are in my site.master file)

<!-- jQuery --> 
    <script src="<%= Url.Content("~/scripts/jquery-1.6.2.js") %>" type="text/javascript"></script> 
    <script src="<%= Url.Content("~/scripts/jquery-1.6.2.min.js") %>" type="text/javascript"></script> 
    <!-- /jQuery--> 

    <!-- jQuery UI --> 
    <script src="<%= Url.Content("~/content/script/jquery-ui-1.8.16.custom.min.js") %>" type="text/javascript"></script> 
    <link href="<%= Url.Content("~/content/css/cupertino/jquery-ui-1.8.16.custom.css") %>" rel="stylesheet" type="text/css" media="screen" /> 
    <!-- /jQuery UI --> 

I hope I haven't missed out anything but if I have ask and I shall provide.

+0

クイックポイントはそれをやった、次の2つのjQueryのスクリプトを必要としません。あなたは1つだけ必要です。最小のものは圧縮されていないコードまたは開発コードであり、最小のものは圧縮のためのコードです。 – NebulaFox

+0

は今のところmin版を削除しましたが、私は1を追加するのと同じ方法で数字を削除する方法を考えましたか? (これによって私はちょうどそれがうまくいけばonclickの出来事にあることを意味する) – Myzifer

答えて

1

append can't be used in your case since it will append something to the text inside some element, whereas in your case you are adding text into textbox which should use text property to access its content.

CORRECTED VERSION:

onclick= "$('#TBBlah').val($('#TBBlah').val() + $(this).text())" ; 

This will append the newly clicked number to the value inside textbox.

+1

私はそれがいかに働くかかなり見ない。文字列が不変であるため、 '#TBBlah'の' text'を取得して 'this'の' text'に追加するので、 '#TBBlah'の結果は変更されません。 – NebulaFox

+1

そして 'text'は' append'と同じように動作します。タグの間にテキストを置くか、タグの間のテキストを取得します。 – NebulaFox

+0

ええ私はちょうど無効なコードとこのコードを使用するためのさまざまな方法を試し終わったと何も動作します。手始めに は、あなたがそう、私は$(この)は.text()にそれを入れてみましたテキストボックスに入力するテキストに値を代入する場所を示していないようです。私は今、私が気づいたので、私はバージョンを修正したので、私はそれが働くようにしてネブラファックスの解決策を見てみることを試みるでしょう。 – Myzifer

0

It help to find out what HTML.TextBox actually created was an input field. You don't want to append, wich adds stuff between two tags you want to add the to the input value. So

onclick="$('#TBBlah').val('7');" 

Here's a link for you: http://api.jquery.com/val

を使用して、テキストボックスに、道の値を.appendする方法

onclick="$('#TBBlah').val($(this).text());" 
関連する問題