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
Instead of Downloading, Files Are Opening in Browser
Javascript: Location.Href to Open in New Window/Tab
How to Restrict Past Dates in Html5 Input Type Date
How to Reset the Bootstrap Modal When It Gets Closed and Open It Fresh Again
React Button Onclick Redirect Page
How to Get Around .Push Is Not a Function in JavaScript
Get List of Filenames in Folder With JavaScript
Stringified Json Has Unwanted Double Quotes
Filtering Multiple Items With Es6 Array Functions
How to Detect Browser Back Button Click Event Using Angular
Regex to Remove Certain Characters At the Beginning and End of a String
How to Download Fetch Response in React as File
How to Convert Jquery Code to JavaScript
How to Detect Browser Refresh Using Angular
How to Tell If a String Contains a Certain Character in JavaScript
Nosuchelementerror: Unable to Locate Element - Selenium Webdriver Using JavaScript