i need one form textbox value change, In that value pass into another form textbox in my website....

Recommended Answers

All 4 Replies

I have tried below code .. its working fine and textbox value should be passing in same form ....but i need one textbox to be one form and another text box to be in another form value should be passed....
$(document).ready(function()
{ $("#query2").blur(function(e)
{
$("#search_head #query").val($(this).val()); }); });


<form id="search_head">

    <input id="query" />
    <input id="query2" placeholder="Blur me" value="Hi there" />
</form>
Member Avatar for diafol

Use .change() .For text boxes, you probaby won't see any difference though.

JS

$('#query2').change(function(){$('#query').val($(this).val())});

HTML

<form>
    <input id="query">
</form>

<form>
    <input id="query2">
</form>

However, if these are on different pages i.e. you need to submit to the server, this won't work. But then you didn't say that.

@diafol thanks for your response ..yeah i need to code for not same page , these two textboxes are diffrent page and how to change textbox1 value should be affected in another form value of textbox2 ??? that only i needed ...

Member Avatar for diafol

OK, assuming you are submitting the first form normally (submit button->server->operations->response [e.g. serve new page with 2nd form]).
This will have nothing to do with jQuery, unless you want to use webstorage - which I wouldn't suggest for this. It's pure PHP.

You can store the changed data "permanently" in a DB or file or you can store it temporarily in a COOKIE or a session variable. It depends on what the change is supposed to do. If it is part of a 'wizard' or multi-step type form, then you may want to use a session variable. If it is like a change of address, then this would be a permanent change, so use a DB. These are pretty loose rules, since there are many exceptions.

handlers/firstformhandler.php

<?php
session_start();
if($_POST && isset($_POST['query']))
{
    $_SESSION['query_val'] = $_POST['query'];
    $loc = '../secondform.php';
}else{
    $loc = '../firstform.php';
}
header("Location: $loc" );
exit;

secondform.php

<?php
session_start();
$qryVal = '';
if(isset($_SESSION['query_val']))
{
    $qryVal = $_SESSION['query_val'];
    unset($_SESSION['query_val']);
}
?>

<!-- later on -->
<form>
    <input id="query2" value="<?=$qryVal?>" />
</form>

Many variations of this type of thing.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.