0

2 pages index.php and function.php

how to transfer the chosen value of input

like this <input type = "text" name = "skill" value = "<?php value autocomplete ?>" />

on page

index.php

there is this code

<html>
<head>
<script type="text/javascript" src="jquery.js"></script>
<script type='text/javascript' src='jquery.autocomplete.js'></script>
<link rel="stylesheet" type="text/css" href="jquery.autocomplete.css" />

<script type="text/javascript">
$().ready(function() {
    $("#skill").autocomplete("get_list.php", {
        width: 260,
        matchContains: true
    });
});
</script>
</head>
<body>

<input type="text" name="skill" id="skill" />

</body>
</html>

and on page function.php

<?php 
$form = '
<div name="input" class="input_box" id="input">
<form action="function.php" target="iframe" enctype="multipart/form-data" method="post" >
....
<div style="padding-right: 14px;">

<input type="text" name="skill" value="value from autocomplete" />

</div>
 ...
</form>
</div>
    ';
?>

on page index.php, i have the autocomplete, i chose value from <input type = "text" name = "skill" id = "skill" />

how to transfer the chosen value of input (index.php) <input type = "text" name = "skill" id = "skill" /> to page function.php to <input type = "text" name = "skill" value = "chosen value from autocomplete (index.php)" />

like this <input type = "text" name = "skill" value = "<?php value autocomplete ?>" />

Max
  • 17
  • 6

1 Answers1

0

You can use ajax to post the value there but you have to get that with:

$("#skill").autocomplete("get_list.php", {
    width: 260,
    matchContains: true,
    select: function( event, ui ) {
       $.post('path/to/function.php', {"selected":ui.value}, function(data){
           console.log(data); // check the data if returns anything.
       });
    }
});

now in the function.php:

<?php 

$form = '<div name="input" class="input_box" id="input">'.
            .........
'<input type="text" name="skill"' . 
'value="'.isset($_POST['selected']) ? $_POST['selected'] : 'default text' . '" />';

</div>
 ...
</form>
</div>';
?>
Jai
  • 74,255
  • 12
  • 74
  • 103