Radio Button In Form Function With Javascript [closed] - javascript

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 7 years ago.
Improve this question
I use this code to make simple form function with javascript, but doesn't work correctly.
(function(){
var o=document.getElementById('formsz');
o.getElementsByTagName('form')[0].onsubmit=function(){
if(this.version.value == "show"){
alert("show")
}else{
alert("hide")
}
return false
}})();
<div id="formz">
<form action='#'>
<input type="radio" name="version" id="x64" value="show">Show<br/>
<input type="radio" name="version" id="x32" value="hide">Hide<br/>
<button type='submit'>Login</button>
</form>
</div>
Whats wrong?? Why it doesn't work ??? Please help,,,

'formzs' !== 'formz' - .getElementById is finding nothing because you've passed the wrong ID in.
Try using your developer console next time, the error is pretty obvious.
(function(){
var o = document.getElementById('formz');
o.getElementsByTagName('form')[0].onsubmit=function(){
if(this.version.value == "show"){
alert("show")
}else{
alert("hide")
}
return false
};
})();
<div id="formz">
<form action='#'>
<input type="radio" name="version" id="x64" value="show">Show<br/>
<input type="radio" name="version" id="x32" value="hide">Hide<br/>
<button type='submit'>Login</button>
</form>
</div>

Related

How to debug non-working jQuery on mobile devices? [closed]

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 6 years ago.
Improve this question
This is my JavaScript code which is not executing properly. I think I am getting something wrong somewhere.
I want to add a search bar to make a search option in a responsive menu navbar. However, it is showing in desktop but not in mobile menus. That's why I am using jQuery to add this manually.
$(document).ready(function() {
$('ul').append("
<li class='fusion-custom-menu-item fusion-main-menu-search fusion-last-menu-item'>
<a class='fusion-main-menu-icon'></a>
<div class='fusion-custom-menu-item-contents'>
<form action='http://www.heilmancenter.com/' method='get' class='searchform' role='search'>
<div class='search-table'>
<div class='search-field'>
<input type='text' placeholder='Search ...' class='s' name='s' value=''>
</div>
<div class='search-button'>
<input type='submit' value='' class='searchsubmit'>
</div>
</div>
<input type='hidden' value='en' name='lang'>
</form>
</div>
</li>
");
});
remove new lines from the html: either concat all lines or put your html code in one line
The first problem is that you mispelled the function keyword, the second one is that you are creating a mult-line string, but the engine doesn't know it and interprets the second line as a instruction. You need to take a precaution, such as add a backslash at the end of any line.
jQuery(document).ready(function(){
jQuery('ul').append("<li class='fusion-custom-menu-item fusion- main-menu\
-search fusion-last-menu-item'><a class='fusion-main-menu-icon'></a><div\
class='fusion-custom-menu-item-contents'><form\
action='http://www.heilmancenter.com/' method='get' class='searchform'\
role='search'>\
<div class='search-table'>\
<div class='search-field'>\
<input type='text' placeholder='Search ...' class='s' name='s'\
value=''>\
</div>\
<div class='search-button'>\
<input type='submit' value='' class='searchsubmit'>\
</div>\
</div>\
<input type='hidden' value='en' name='lang'></form>\
</div></li>");
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>

Php : cant sumbit the good form [closed]

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 6 years ago.
Improve this question
Sorry for my spelling
Hi, im trying to make a website showing internet forfeit, so in mySQL database i put all my information then I print it on my web page, the the user click on the forfeit he wants, it brings him to an other page that shows all the forfeit informations... In the while(), I'm making unique form for each forfeit, then on the
The problem here is that the only form sumbitted is the last one created
include_once "DataBase/db.php";
if($internet->num_rows != 0){
while($rows = $internet->fetch_assoc()){
$nom = $rows["nom"];
$id = $rows["id"];
$tech = $rows["technologie"];
$telechargement = $rows["telechargement"];
$televersement = $rows["televersement"];
$utilisation = $rows["utilisation"];
$prix= $rows["prix"];
echo '
<form method="POST" action="Fournisseurs/Videotron.php" id="'.$id.'">
<div class="boxes">
<div class="[ price-option price-option--high ]">
<div class="price-option__detail">
<span class="price-option__cost">'.$nom.'<br>$'.$prix.'</span>
</div>
<input type="hidden" name="id" value="'.$id.'"></input>
<input type="hidden" name="nom" value="'.$nom.'"></input>
<input type="hidden" name="tech" value="'.$tech.'"></input>
<input type="hidden" name="telechargement" value="'.$telechargement.'"></input>
<input type="hidden" name="televersement" value="'.$televersement.'"></input>
<input type="hidden" name="utilisation" value="'.$utilisation.'"></input>
<input type="hidden" name="prix" value="'.$prix.'"></input>
<div class="price-option__purchase">
Submit
</div>
</div>
</div>
';
}
}
You can see what i'm talking about here : http://fournisseursquebec.com/Forfaits.php
just select internet
Thank you!
You are missing the closing </form> tag for every box. Now you have one big form with a lot of repeated fields:
<form method="POST" action="Fournisseurs/Videotron.php" id="'.$id.'">
box 1:
<input type="hidden" name="id" value="'.$id.'"></input>
.... box 2:
<input type="hidden" name="id" value="'.$id.'"></input>
...
The name attribute of the various input is the one that is sent and should be unique inside every form.
Just add the </form> tag in your while loop and it should work.

jquery - hide unchecked radio button using submit button [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Closed 6 years ago.
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.
We don’t allow questions seeking recommendations for books, tools, software libraries, and more. You can edit the question so it can be answered with facts and citations.
Improve this question
I want to hide all unchecked radio button and its label then display only the checked radio button using the submit button click event.
<form method="post">
<input type="radio" name="radiobtn">
<label for="first">First</label>
<input type="radio" name="radiobtn">
<label for="second">Second</label>
<input type="radio" name="radiobtn">
<label for="third">Third</label><br>
<input id="submit" type="submit">
</form>
I want to make this work using jQuery. Can anyone give me snippet of jQuery code on how to do this?
Do something simple like this
$('#submit').click(function(e) {
e.preventDefault(); // prevent the form submission
$('[name="radiobtn"]:not(:checked)') // get all unchecked radio
.hide() // hide them
.next() // get all label next to them
.hide(); // hide the labels
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<form method="post">
<input type="radio" name="radiobtn">
<label for="first">First</label>
<input type="radio" name="radiobtn">
<label for="second">Second</label>
<input type="radio" name="radiobtn">
<label for="third">Third</label>
<br>
<input id="submit" type="submit">
</form>

Click on an element: copy its text to an input field [closed]

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 years ago.
Improve this question
I searching a method to copy text to an input field, text can be in some tag or - it doesn't matter, but after clicking on this value I need to put this to input field (type text). I think it is possible with JavaScript/jQuery, but I don't know how to write script like this.
Just look at this example
HTML PART
<div class="copy">Copy me</div>
<span class="copy">Hey copy me</span>
Me too
<input type="text" class="paste" value="" />
JQuery PART
$(document).on('click', '.copy', function(e){
e.preventDefault();
$('.paste').val($(this).text());
});
SEE IN ACTION
Give unique id to your input text
for example
and in OnClick event function write following line of code
$("#1").val('some text');
Actually I am not clear about question. Anyway please find below working Fiddle,
Fiddle Here
<input type="text" id="txt_name" placeholder="Enter text to copy"/>
<br>
<br>
<input type="text" id="txt_name_copy" placeholder="Copied Text Here..."/>
<input type="button" id="btn_Run" onclick="fn_copy();" value="Copy Text"/>
Function here :
function fn_copy()
{
var temp = document.getElementById("txt_name").value;
if(temp != "")
{
document.getElementById("txt_name_copy").value = temp;
}
else
alert("Text is Empty");
}

javascript with checkbox to count and hide/show [closed]

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 8 years ago.
Improve this question
i need help to make one script
The script I'm trying to do is the following:
I have a page with multiple checkbox's corresponding products and they all have an associated value.
  then I have a variable that is the value I have in the account, and what I wanted to do with that as I start choosing products by clicking on the checkbox, javascript would have to count the value that has already been chosen and see how and lacking and hide all products that have a higher value or have available
<?php
$totalmoney = '50';
?>
<div class="tags">
<label><input type="checkbox" id="arts" value="20" /> Arts </label>
<label><input type="checkbox" id="computers" value="40" /> Computers </label>
<label><input type="checkbox" id="phone" value="15"/> Phone </label>
<label><input type="checkbox" id="video-games" value="5" /> Video Games </label>
</div>
Help me please, i need this to my work :S
Start with calculating the values of selected checkboxes with JS something like this:
var $inputs = $('#arts,#computers,#phone,#video-games');
$inputs.on('click', function (event) {
$checked = $inputs.is(':checked');
totalChecked = 0;
$checked.each(function () {
totalChecked += $(this).val();
});
});
Now you can easily check the rest:
var toBeSpend = totalmoney - totalChecked;
$inputs.not(':checked').each(function () {
$(this).toggle($(this).val() > toBeSpend);
});

Categories

Resources