suppose I have front end and backend like this: html: <div class="col-xs-4"> <h5…
- User
suppose I have front end and backend like this:
html:
javascript: async function addBug(id, des, critical) { let form = document.getElementById('add-bug-container'); document.getElementById('new-bug1').value = ''; document.getElementById('new-bug2').value = ''; document.getElementById('new-bug3').value = ''; form.classList.remove('was-validated'); contract.methods .getBugCount() .call({ from: web3.eth.defaultAccount }) .then( (bugNum) => { addBugToList(bugNum, name, false); }, (err) => { console.log('Failed to retrieve the number of bugs from Ganache.'); } ); try { await contract.methods .addBug(name, id, critical) .send({ from: web3.eth.defaultAccount }); } catch { console.log('Failed to save bug to blockchain.'); } }
I want the addBug function could capture html form input to send to Ethereum testnet.
- Assistant
- User
<button type=“submit” data-dismiss=“modal” class=“btn btn-success” onclick=“addBug(document.getElementById(‘new-bug1’).value, document.getElementById(‘new-bug2’).value, document.getElementById(‘new-bug3’).value);”>Save
js code in html seems strange
- Assistant
It looks like your concern is regarding the use of quotation marks in the
buttonelement'sonclickattribute. The quotation marks used in the provided code snippet are “curly” or “smart” quotes, which are typographically different from the "straight" quotes expected in HTML and JavaScript code. This can happen when copying and pasting code from certain text editors or word processing software that automatically converts straight quotes to curly quotes.To fix the issue, you need to replace the curly quotes with straight ones. Here's the corrected
buttonelement:<button type="submit" data-dismiss="modal" class="btn btn-success" onclick="addBug(document.getElementById('new-bug1').value, document.getElementById('new-bug2').value, document.getElementById('new-bug3').value);">Save</button>Also, ensure that the rest of your HTML and JavaScript code uses straight quotes to prevent syntax errors. Always use a code-friendly text editor that doesn't automatically convert these quotes to ensure the integrity of your code syntax.