0

I have text box on 1.php like this

<input type="text" id="1" value="somevalue">

&

text box on 2.php like this

<input type="text" id="2" value="">

1.php and 2.php resides on single domain.

I want to get value of textbox1 into textbox2 using jQuery

How can I achieve this ?

Thanks

4
  • 1
    Are these on different pages? (Or a related <iframe>?) Are they pre-populated? Also in HTML4 IDs can't start with a number :) Commented Aug 9, 2010 at 10:34
  • @Nick Craver, they are diffrent pages....something with .get() ; Ohh.. In this example I used ID's .... :) Commented Aug 9, 2010 at 10:39
  • I mean your browser, you're currently at http://mysite.com/1.php right, that's the main page which is doing the loading of 2.php? Commented Aug 9, 2010 at 10:46
  • The question I want to ask is how is value for 2.php generated? Commented Aug 9, 2010 at 15:06

2 Answers 2

1

If I understand the question correctly, you can do this:

$.get('2.php', function(data) {
  var newVal = $('#2', data).val();
  $('#1').val(newVal);
});

We're forgetting the IDs are numbers, it's just an example here. All we're doing is passing a context option to $(selector, context) to find the ID within the response, and taking its .val() for use.

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

Comments

0

You can do something like this.

1) Create a div in 2.php

  <div id="mydiv">
  </div>

2) Load the element onto div

  $('#mydiv').load('1.php #<id-in-1.php>'); 
  <!-- note.. pls use correct id tags.. ids can't start with numbers-->

3) and then access the value by using

    $('#mydiv input').val();

1 Comment

I added a bit of formatting so this is easier to read...markdown doesn't format property if a codeblock follows a number scheme, so you have to number yourself in those cases :)

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.