开发者

input text change onclick button value

Actually i want to create a page switcher, all i need for this is an input with type text where will be entered the number of the page, and i have the second input with type button and onclick开发者_StackOverflow中文版 value:

<input type="text" value="#number of the page#" />
<input type="button" onclick="_go_page_('cf_pages_form_name1','#number of the page#');" />

I cant figure it out how to take this #number of the page# and put it in onclick dynamically using javascript... please smb help!


<input type="text" id="txtPageNumber" value="2" />
<input type="button" id="btn" value="click" onclick="_go_page_('cf_pages_form_name1','#number of the page#');" />


$(document).ready(function(){

    $("#btn").click(function(){

       var $val = $("#txtPageNumber").val();
        alert($val);
            _go_page_('cf_pages_form_name1',$val);

    });


});




});


Assuming number is the id of the text field.

You can get the value of the text field like this:

$('#number').val();

And pass that is the onclick event


You can use an ID on the page selector input to get the value.

function goToPage(pageNumber) {
  // go to pageNumber
}

&lt;input type="text" id="pageSelector" value="#number of the page#" />
&lt;input type="button" onclick="goToPage($('#pageSelector').val())" />

You've tagged this with jQuery so I'm assuming you're using jQuery.


lets your input type is like this

then in jquery try something like this...

$('#pageNo').keyup(function(){
 pageNo =    $(this).val()
 }

then pass this to your button onclick function


i will answer in "very easy to understand" without jquery:

you have to get the value of the first inputfield. this should your function do. but first the inputfield needs an id(f.g. 'number').

code in function:

var pagenumber = document.getElementById('number').value;

then you have to put the number into the url (document.href).

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜