0

Alright, so I'm not sure if I should be asking this here or HTML/JavaScript forums, so please do let me know if I am in the wrong place. I believe it belongs here as you all understand dApps and Solidity.

How can I make it so that when an user inputs a string in my dApp, I add the double quotation marks to it before passing the string onto the smart contract's function?

So, what I have now is a dApp that uses the HTML input tag to gather a string that is a parameter of a function in my smart contract. However, for the calling of the function to work, I need to add double quotation marks to the string, so that the contract recognizes this.

I don't want users to have to add the quotation marks, so I'd like to "pre-add" them, either on HTML or JavaScript, without the user seeing them there. Any suggestions on how to do this? Current code below:

HTML input tag:

<input id="string" type="text">

JQuery code:

  $("#button2").click(function(web3) {
     var tx = Contract.function($("#string")[0].value, { 
         from: address,
         gas: "3000000",
         to: "Contract address here",
         value: "0",
         data: ""
  }, function(err, transactionHash) {
   if (!err)
        console.log(transactionHash); 
    })
})

closed as off-topic by Ismael, Achala Dissanayake, shane, flygoing, ivicaa Sep 25 '18 at 19:26

This question appears to be off-topic. The users who voted to close gave this specific reason:

  • "This question does not appear to be about Ethereum, the decentralized application platform and smart contract enabled blockchain, within the scope defined in the help center." – Ismael, Achala Dissanayake, shane, flygoing, ivicaa
If this question can be reworded to fit the rules in the help center, please edit the question.

1

Change

var tx = Contract.function($("#string")[0].value,

To

 var tx = Contract.function("\"" + $("#string")[0].value + "\"", 
  • Thank you, that works! I'm not too familiar with JavaScript so didn't know how to apply escape characters there. – Yakko Majuri Sep 23 '18 at 14:37

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