Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 8 years ago.
Improve this question
I'm trying to set the value of a text input field when someone clicks anchor/button. Right now I have this:
<head>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<script>
$(document).ready(function(){
$("#text-add").click(function(){
$("#domain-pick").val("test");
});
});
</script>
</head>
<a id="text-add" href="javascript:void(0);">Click Here</a>
<input type="text" name="text-field" id="domain-pick">
I got it working in Jsfiddle, but it will not work on my wordpress site!
Please refer this fiddle.
Note:
You don't need to wrap the function in document.ready if you are
script appears after the markup.
Please avoid inline javascript, like javascript:void(0);
Markup:
<a id="text-add" href="#">Click Here</a>
<input type="text" name="text-field" id="domain-pick">
JS:
$("#text-add").on('click', function(e){
e.preventDefault();
e.stopPropagation();
$("#domain-pick").val("test");
});
Related
Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed last year.
Improve this question
The error ReferenceError: b is not defined at HTMLButtonElement.onclick (/:32:30)
let s;
function b(){
s = document.getElementById(k).innerHtml;
animates();
}
<form class="form">
<label>How much do you want to donate</label>
<input type="number" id="k">
<button id="l" onclick="b()">Cal</button>
</form>
no need to do a form for this, also inline events are not preferred use eventListeners in js.
NOTE: I've put input's value as result, but you didn't say what you exactly want, so I think this will work with you anyway
document.getElementById('l').addEventListener('click', function() {
document.getElementById('result').innerHTML =document.getElementById('k').value;
})
<label>How much do you want to donate</label>
<input type="number" id="k">
<button id="l">Cal</button>
<p id="result"></p>
Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 5 years ago.
Improve this question
I would like to use jQuery to update value of attribute "accept" of an input element with type = "file", then active the "click" event of it. But after the value of "accept" is changed, nothing happens.
This is my code
//html elements
<button type="button" class="abc" title="Select files from your computer" id="upload" onclick="updateExtension()"></button>
<input type="file" name="image" id="image" multiple="multiple" /> //this input field is hidden and is applied with jquery-file-upload
//jQuery function
function updateExtension(){
$('#image').attr('accept', '.jpg, .png');
$('#image').click();
}
You can simply use :
$( "#image" ).trigger( "click" );
For more information on jQuery trigger click here.
Simple way use this one:--
<!DOCTYPE html>
<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
<script>
$(document).ready(function(){
$("#click").click(function(){
//if update(div)content
$(".update_new_value").html("<h1>Enter content</h1>");
//if change attr value
$("#urls_change").attr("href", "https://www.changers.com/");
});
});
</script>
</head>
<body>
<div class="update_new_value"></div>
<p>change urls</p>
<button name="btn" id="click" type="button">Click Me</button>
</body>
</html>
Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 5 years ago.
Improve this question
This is a copy of an HTML document from a tutorial on Javascript. Upon opening it in Chrome, it doesn't behave as intended. When I click the button with Set Cookie written on it, nothing shows up, regardless of whether I have written something in the box (we should get output on the page) or not (we should get an alert). Why?
<!DOCTYPE html>
<html>
<head>
<script type="text/javascript">
<!--
function WriteCookie()
{
if( document.myform.customer.value == ""){
alert("Enter a name");
return;
}
cookievalue = escape(document.myform.customer.value) + ";";
document.cookie="name=" + cookievalue;
document.write("Setting Cookies : " + document.cookie);
}
//-->
</script>
</head>
<body>
<form name="myform" action ="">
Enter name: <input type="text" name="customer"/>
<input type="button" value="Set Cookie" onlick="WriteCookie();"/>
</form>
</body>
</html>
You have a typo in your input box. It should read:
<input type="button" value="Set Cookie" onClick="WriteCookie();"/>
Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 8 years ago.
Improve this question
here is my table:
<ul class="vertical-tabs-list">
<li class="vertical-tab-button first selected">blah</li>
<li class="vertical-tab-button">blah</li>
</ul>
I want to append another li like so:
$(".vertical-tabs-list").append('<li><input type="submit" name="op" id="edit-save" value="Save" class="form-submit"</li>');
What am I doing wrong?
Try this
$("ul.vertical-tabs-list").append('<li><input type="submit" name="op" id="edit-save" value="Save" class="form-submit" /></li>');
This has HTML with no syntax errors and a more specific selector. If that doesn't work check to make sure you have jquery properly linked up with your page.
Also, are you using a document ready function?
$(document).ready(function() {
//your code here
$("ul.vertical-tabs-list").append('<li><input type="submit" name="op" id="edit-save" value="Save" class="form-submit" /></li>');
});
Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 8 years ago.
Improve this question
I want to create a button which allows me to go to a link entered in an input filed.
So this is what I did but it does not work.
<html>
<head>
</head>
<body>
<form action="link">
link : <input type="text" id="link">
<input type="button" value="go" onclick="self.location.href = 'docuement.getElementById('link').value'"/>
</form>
</body>
</html>
What should I do?
Don't use a string literal, get rid of the ' from around the value you assign to self.location.href.
Spell document correctly
You should avoid using self as well, it is an unnecessary level of indirection.
<input type="button" value="go" onclick="location.href = document.getElementById('link').value"/>
Things fixed:
fix spelling of document
unquote the expression to be evaluated
don't bother with self