Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Closed 9 years ago.
Questions concerning problems with code you've written must describe the specific problem — and include valid code to reproduce it — in the question itself. See SSCCE.org for guidance.
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
Improve this question
I work for a nascent online retailer in Ghana, West Africa. We purchased an E-commerce template from Big Commerce. On our website there's a text-field where users are allowed to enter their email addresses and receive newsletters subsequently. Unfortunately, when users enter information, its not seen at the back end. They don't receive the automatic email once they hit enter. i suspect there's something wrong with Javascript code. Please advise:
<script type="text/javascript">
//
$('#subscribe_form').submit(function() {
if($('#nl_email').val() == '') {
// alert('You forgot to type in your email address.');
$('#nl_email').focus();
return true;
}
if($('#nl_email').val().indexOf('#') == -1 || $('#nl_email').val().indexOf('.') == -1) {
//alert('Please enter a valid email address, such as john#example.com.');
$('#nl_email').focus();
$('#nl_email').select();
return true;
}
// Set the action of the form to stop spammers
$('#subscribe_form').append("<input type="hidden" name="check" value="1" />");
return true;
});
</script>
Syntax error here
$('#subscribe_form').append("<input type="hidden" name="check" value="1" />");
Fix:
$('#subscribe_form').append("<input type='hidde' name='check' value='1' />");
Try putting:
$('#subscribe_form').append("<input type="hidden" name="check" value="1" />");
as
$('#subscribe_form').append('<input type="hidden" name="check" value="1" />');
or it will raise an error because of the quotes...
Related
Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 8 months ago.
Improve this question
I am trying to make a registration page for my website but when I run it; it gives error. What am I doing wrong?
<?php
//Form values
$name_value=$_POST['Name_input'];
$Username_value=$_POST['Username_input'];
$DOB_value=$_POST['DOB_input'];
$Password_value=$_POST['Password_input'];
$Phone_number_value=$_POST['Phone_number_input'];
$Python_checkbox_value=$_POST['Python_checkbox'];
$Java_checkbox_value=$_POST['Java_checkbox'];
$C_sharp_checkbox_value=$_POST['C#_checkbox'];
$HTML_checkbox_value=$_POST['HTML_checkbox'];
$Cpp_checkbox_value=$_POST['C++_checkbox'];
$R_checkbox_value=$_POST['R_checkbox'];
$swift_checkbox_value=$_POST['swift_checkbox'];
$kotlin_checkbox_value=$_POST['kotlin_checkbox'];
$JS_checkbox_value=$_POST['JS_checkbox'];
Take a look at this code :
<form method="GET">
<input type="checkbox" value="value" name="name">checkbox label</input>
<input type="submit">
</form>
<?php
if (isset($_GET["name"]))
{
echo $_GET["name"];
}
?>
As you can see when I submit the form without checking, the parameter in URI is empty because the checkbox isn't defined (I used GET method)
But when I check it, you can see the parameter is name=value
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 9 years ago.
Improve this question
I am working on an input box for a promo code. We have several promo codes. However, on one promo code, if the user types in "springchicken", then I need it to open, or toggle an additional radio input for a selection. Is that possible? I am thinking I could use onType, but I don't really know how to write that. See example below. I need it to so something like that but the words that are typed must match "SpringChicken". How can I write that?
<input type="text" name="promo" id="promo" value="" size="22" placeholder="Enter Promo Code" ontype="document.getElementsByClassName('promoradio')[0].style.display='block';" />
<!--Need the following DIV to appear once "SpringChicken" is entered on the fly-->
<div class="promoradio">
<input type="radio" name="promopkg" value="1" /><label>Promo Package #1</label>
<input type="radio" name="promopkg" value="2" /><label>Promo Package #2</label>
</div>
Try this jquery solution: (Edited so it won't be case sensitive)
<script type="text/javascript">
$(document).ready(function () {
$("#promo").keyup(function() {
var value = $(this).val().toLowerCase();
if (value == "springchicken") {
$(".promoradio").show();
} else {
$(".promoradio").hide();
}
});
});
</script>
There are a couple things wrong here.
First, there is no ontype event for javascript. You'll want onkeypress (for when they key goes down) or onkeyup for when the key goes up.
Second, inline javascript is ugly and bad practice. Use something like this:
var x = document.getElementById("input element");
x.onkeyup = function() {
var word = x.innerHTML;
if (word.toUpperCase() === "SPRINGCHICKEN") { //if you're not worried about case sensitivity or unicode
document.getElementsByClassName('promoradio')[0].style.display='block';
}
}
Assuming the class promoradio has display:hidden here initially.
Try this,
<input type="text" name="promo" id="promo" value="" size="22" placeholder="Enter Promo Code" />
<!--Need the following DIV to appear once "SpringChicken" is entered on the fly-->
<div class="promoradio">
<input type="radio" name="promopkg" value="1" /><label>Promo Package #1</label>
<input type="radio" name="promopkg" value="2" /><label>Promo Package #2</label>
</div>
<script>
var textToMatch = "springchicken";
function matchWord(e){
if(document.getElementById('promo').value.trim().toLowerCase() == textToMatch){
document.getElementsByClassName('promoradio')[0].style.display='block';
}else{
document.getElementsByClassName('promoradio')[0].style.display='none';
}
}
document.getElementById('promo').onkeyup = matchWord;
</script>
css:
.promoradio{
display:none;
}
Check fiddle
Hope it helps.
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
I want to clear the email input box when function(data) is greater than zero. The user will have to be force to re-enter another email address since the form will not submit if any fields are blank. how would I clear out the input box?
javascript:
$("#email").change(function(){
var email=$("#email").val();
$.ajax({
type:"post",
url:"/files/reg_check.php",
data:"email="+email,
success:function(data){
if(data == 0){
$("#email_msg").html("E-mail Address must be valid");
} else {
$("#email_msg").html("<div class='msg_check_red'>Error: E-mail address already in use.</div>");
}
}
});
});
html:
<label>E-mail:</label>
<input type="email" placeholder="your#email.com" id="email" name="add[email]" size="20" title="A valid email address required" class="{validate:{required:true,email:true}}" />
<span class="rsmall"><div id="email_msg">E-mail Address must be valid</div></span><br />
Use $("#email").val("");, which sets the value of the input to an empty string.
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 }
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
<form action="javascript:message();">
<input type="text" id="#msg" value='test'>
</form>
This is a simple form I made. Now when I call my JS function using this code it works (only one input can be accessed though):
function message() {
alert($('input').val());
}
But using this code doesn't work (alerts Undefined):
function message() {
alert($('#msg').val());
}
I have really no clue what to do and I have been looking for hours...
The value of the id attribute shouldn't start with a #:
<form action="javascript:message();">
<input type="text" id="msg" value='test'>
</form>
Here's the fiddle: http://jsfiddle.net/XrJjU/
If, for whatever reason, there is a # in the id, you'll have to escape it in your selector:
$('#\\#msg').val();
Here's the fiddle: http://jsfiddle.net/7P5ER/