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();"/>
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 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 7 years ago.
Improve this question
i can't seems to validate the percentage.
Need you guys help me to solve!
function validate()
{
s
if( document.myForm.outputPercentage.value <= 0||>=100
{
alert( "Please the correct percentage." );
document.myForm.outputPercentage.focus() ;
return false;
<form name="myForm" onsubmit="return(validate());">
Last output percentage: <input type"text" name="outputPercentage" id="outputPercentage" />&<br/><br/>
<input type="submit" value="Submit" />
I've corrected your code so that it works:
<html>
<head>
<script type="text/javascript">
function validate() {
var outputPercentageString = document.myForm.outputPercentage.value;
var outputPercentage = parseInt(outputPercentageString);
if (outputPercentage <= 0 || outputPercentage >= 100) {
alert("Please the correct percentage.");
document.myForm.outputPercentage.focus();
return false;
}
}
</script>
</head>
<body>
<form name="myForm" onsubmit="return(validate());">
Last output percentage: <input type="text" name="outputPercentage" id="outputPercentage" />%
<br/><br/>
<input type="submit" value="Submit" />
</form>
</body>
</html>
Remove the 's' all on its own.
Everything on a web page is a String, so to compare the percentage to a number you have to use parseInt to make it into a number.
type"text" should be type="text"
if you open a bracket { then you must close it afterwards }
Put the javascript into <script> tags in the <head> element of the page
I've put everything into <html> elements.
Learn what getElementById() does. Everybody uses ids to get references to webpage elements rather than names.
Hope this helps.
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");
});
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
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
The problem is nothing validates. I can leave the form empty and it gives no alert
<html>
<body>
<script src="http://code.jquery.com/jquery-latest.min.js"></script>
<script type="text/javascript">
function validateForm() {
var x = document.forms["myform"]["fname"].value;
if (x == null || x == "") {
alert("Enter your certificate address first.");
} else if(!x.match(/facebook/g) || !x.match(/access_token/g)) {
alert("Invalid certificate address, please try again...");
return false;
}
)
</script>
<form name="myform" action="welcome.php" method="post" onsubmit="return validateForm();">
Name: <input type="text" name="fname">
<input type="submit" value="submit">
</form>
</body>
</html>
not sure what is wrong with this. looks pretty straitforward
Missing your last end bracket. Changes ) to }