views:

83

answers:

2

Hello,

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

A: 

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();
JWhiz
@JWhiz - 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 :)
Nick Craver
@ Nick - Excellent.. Thanks
JWhiz
+1  A: 

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.

Nick Craver