Pass Parameter from Input to Onclick Method

pass input value to onclick function

In your exportText function, if it's a local function you can directly use

document.getElementById('yourname').value;

instead of 'Name of player' parameter
Now, if it's a global function, you can play with a specific class (Ex:ClsUserName) and in your exportText use

document.getelementsbyclassname('ClsUserName')

How to pass the button value into my onclick event function?

You can pass the value to the function using this.value, where this points to the button

<input type="button" value="mybutton1" onclick="dosomething(this.value)">

And then access that value in the function

function dosomething(val){
console.log(val);
}

Pass a string parameter in an onclick function

It looks like you're building DOM elements from strings. You just need to add some quotes around result.name:

'<input type="button" onClick="gotoNode(\'' + result.name + '\')" />'

You should really be doing this with proper DOM methods though.

var inputElement = document.createElement('input');
inputElement.type = "button"
inputElement.addEventListener('click', function(){
gotoNode(result.name);
});

​document.body.appendChild(inputElement);​

Just be aware that if this is a loop or something, result will change before the event fires and you'd need to create an additional scope bubble to shadow the changing variable.

javascript passing text input to a onclick handler

Give an id to input field:

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

Now modify click handler as follows:

<input type="button" value="Submit" 
onclick="onLoadConfigPress(document.getElementById('configname').value)" />

Or if you have only one form on that page, you could also use forms array:

<input type="button" value="Submit" 
onclick="onLoadConfigPress(document.forms[0].configname.value)" />

Pass input textbox value in onClick function - php

Have you tried writing something like following.

<input type="submit" value="submit" onclick="saveValue(document.getElementById('acre_value').value)">

Is there a way to pass id of input tag as a onclick function parameter without actually writing the id value in JSX?

This should work

<li className="search-list-off">
<label className="container">
<p>First name</p>
<input
id="check-firstname"
type="checkbox"
onClick={(e) => inputAction(e.target.id)} // i dont wanted to write this for each ids
/>
<span className="checkmark"></span>
</label>
</li>


Related Topics



Leave a reply



Submit