contract Student
uint256 index=0;
function Students(bytes32 name, uint256 adNo) returns (uint256 vid)
mapping(uint256 => bytes32) public Name;
mapping(uint256 => uint256) public AdmissionNo;

the return value for vid is like 0xca297a8080be23ace753b20084fd853533af205c16bbfef7aa466208aa0341d5 when printing in html

<script type='text/javascript'>
web3.eth.defaultAccount = web3.eth.accounts[0]
function get() {
    var index = document.getElementById('index').value;
    var name = contracts['Student'].contract.Name(index);
    var adNo = contracts['Student'].contract.AdmissionNo(index);
    document.getElementById('queryres').innerText = hex2a(name)+"   "+adNo;


function set() {
    var name = document.getElementById('name').value;
    var adNo = document.getElementById('adNo').value;
    var res = contracts['Student'].contract.Students(name,adNo);
    document.getElementById('queryres').innerText = res;
    function hex2a(hex)
            //hex = document.calcform.hex.value;
            hex = hex.match(/[0-9A-Fa-f]{2}/g);
            len = hex.length;
            if( len==0 ) return;
            for(i=0; i<len; i++)
                h = hex[i];
                code = parseInt(h,16);
                t = String.fromCharCode(code);
                txt += t;
            return txt;

<body bgcolor='#E6E6FA'>
    <input type='text' id='name'>
    <input type='number' id='adNo'>
    <button onclick='set()'>Save</button>
    <input type='number' id='index'>
    <input value='get' type='button' id='query' onclick='get()' />
    <div id='queryres'></div>

when clicking save button it should save and return index of the student


Transactions don't support return values in web3. The value you're displaying is the transaction hash, not the return value of the function you're calling.

Instead of trying to return the value from the transaction, you need to either provide a separate function call that looks up a record's index, or allow the caller to supply an ID for the record - such as a GUID. If you do the latter, be sure to prevent users from being allowed to overwrite existing records!

| improve this answer | |
  • 2
    Alternatively log an event with the number you want returned and have your javascript listen for that. – Edmund Edgar May 20 '16 at 14:50

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.