0

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 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!

2
  • is #number some variable that contains the page number of the current page?? Commented Feb 3, 2011 at 10:30
  • @3nigma nope, just the number that user will have to enter to go to the page he want Commented Feb 3, 2011 at 10:32

5 Answers 5

1
<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);

    });


});




});
Sign up to request clarification or add additional context in comments.

1 Comment

this is ur code i modified to make it work properly ) <input type="text" id="txtPageNumber" value="" /><input type="button" id="gotoPage" onclick=""/>$("#gotoPage").click(function(){var abr = $("#txtPageNumber").val();_go_page_('cf_pages_form_name1',abr);});
0

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

Comments

0

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.

Comments

0

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

Comments

0

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).

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.