Chriskonz
Chriskonz

Reputation: 199

Passing Value to HTML <input> tag

So I have this code to get the value from the dropdown list and showing the corresponding value to the HTML input tag. I dont know how to pass the values from the drop down the the HTML input tag. Please advise me to do this with the onChange method that when user select one of the values, the input tag gets updated.

my code is

function OnSelectionChange(str){     }

   $(function(){
    //show records
    $('#show').click(function(){
        $.post('data.php',
                            {action: "show", "hm":$('#headmark').val()},
                                      function(res){
            $('#result').html(res);
        });     
    });
});
</script>
<head>
<body>

<?php         
     $result = oci_parse($conn, 'SELECT HEAD_MARK FROM FABRICATION');
     oci_execute($result);

     echo '<SELECT name="headmark" id="headmark"  onchange="OnSelectionChange(this.value)">'.'<br>';
     echo '<OPTION VALUE=" ">'."".'</OPTION>';

     while($row = oci_fetch_array($result,OCI_ASSOC)){
     $HM = $row ['HEAD_MARK'];
     echo "<OPTION VALUE='$HM'>$HM</OPTION>";
     }
     echo '</SELECT><br />';
 ?>

 <!-- MAX PLACEHOLDER SHOULD BE GATHERED FROM THE QUANTITY FROM THE   CORRESPONDING           HEAD_MARK-->
  Cutting: <input name="cutting" type="number" min="currCutting" max="currQty"     id="fcutting" /><br />

<h2>Show Records</h2>
<button id="show">Show</button>
<p>Result:</p>

<div id="result"></div>

and on the update_attribute.php is for querying the cutting value for passing to the min value in the input tag

 <?php

    $sql = "SELECT CUTTING FROM FABRICATION WHERE HEAD_MARK = '".$head_mark."'";

    $data_query = oci_parse($conn, $sql);

    oci_execute($data_query);

    while ($row = oci_fetch_assoc($data_query)){

    }
?>

Upvotes: 0

Views: 211

Answers (2)

Cheong BC
Cheong BC

Reputation: 316

You can store multi value in the OPTION tag, by using the jquery.data() function.

 $HM = $row ['HEAD_MARK'];
 $CT = $row ['CUTTING']; 
 echo "<OPTION VALUE='$HM' data-cutting='$CT'>$HM</OPTION>";

Then your js function should be like below

function OnSelectionChange(str){ 
     var ct = this.data('cutting');
     $('#fcutting').val(str);
     $('#fcutting').attr('min',ct);

}

Note : "data-cutting" must be lowercase in html tag.

Upvotes: 2

Sean
Sean

Reputation: 12433

I assume you are looking for

function OnSelectionChange(str){ 
     $('#fcutting').val(str);
}

where fcutting is the id of your given <input>

Upvotes: 1

Related Questions