logo
down
shadow

How to pass same class/id name php values from radio button to javascript?


How to pass same class/id name php values from radio button to javascript?

By : FMX
Date : November 22 2020, 02:42 PM
around this issue This is my problem. I am looping items from the database that contains items name and id. I have a radio button for each items. The id of that item is stored in the radio buttons value....Now what i want to achieve is when i click on the submit button,it will call a function call save() in javascript and save all the selected items ONLY .... i've been trying this for hours but i cant get it worked. , Without looking into it too much, take a look at this line:
code :
var f = document.getElementsByClassName('item').value;
var checkboxes = document.getElementsByClassName('item');
var f = [];

for(var i = 0; i < checkboxes.length; i++){
   if(checkboxes[i].checked == true)
       f.push(checkboxes[i].value);
}

f = f.join();//makes comma seperated list

//proceed with ajax call


Share : facebook icon twitter icon
How can i pass multiple radio button values to MYSQL Database via PHP as all individual values but keeping them segregat

How can i pass multiple radio button values to MYSQL Database via PHP as all individual values but keeping them segregat


By : user2737814
Date : March 29 2020, 07:55 AM
help you fix your problem I'm not sure if I'm getting the jist of what you trying to do, but it seems like you need to save an individuals answers to different questions to the DB but that each question can only have ONE of let's say three possible answers. Well, in that case you might think of redesigning your DB to look something like this:
code :
<div class="questionBox">
   <p>1.Have I clearly defined my companies target market?</p>
    <input type="radio" name="q1" value="10"/>
      <label for="ca1">YES</label>
  <input type="radio" name="q1" value="5"/>
      <label for="ca1">SOMEWHAT</label>
  <input type="radio" name="q1" value="-10"/>
    <label for="ca1">NO</label>
</div>
<div class="questionBox">
   <p>2.Have I clearly defined my companies product?</p>
    <input type="radio" name="q2" value="10"/>
      <label for="ca2">YES</label>
  <input type="radio" name="q2" value="5"/>
      <label for="ca2">SOMEWHAT</label>
  <input type="radio" name="q2" value="-10"/>
    <label for="ca2">NO</label>
</div>
.....
$radioPost="INSERT INTO answers (user_name, question_name, answer_value)
VALUES (('$_POST[user_name]', 'q1', '$_POST[q1]),('$_POST[user_name]', 'q2', '$_POST[q2]), ....)
$user = $_POST[user_name];
foreach ( $_POST as $key => $val )
{   
    If ($key <> 'user_name') //you might need to check that you only reading the radio                  options
    {
       $radioPost="INSERT INTO answers (user_name, question_name, answer_value)
                   VALUES ('$user', $key, '$val')"
        ....
    }
}    
Is it possible to pass two (2) values from 1 radio button when clicked?

Is it possible to pass two (2) values from 1 radio button when clicked?


By : Udaya Bhaskar
Date : March 29 2020, 07:55 AM
To fix the issue you can do If you can use diffrent prefix with unique separator like underscore() or colon(:) whatever u want in values eg. sleave for sick leave or else
code :
<input type="radio" name="optLeave" value="<?php echo "sleave_".$sLeave; ?>" onclick="disableTextarea()" /><label for="Sick">Sick</label>

<input type="radio" name="optLeave" value="<?php echo "uleave_".$uLeave; ?>" onclick="disableTextarea()" /><label for="Union">Union</label>
//use same separator here
$opt_leave = explode("_", $_REQUEST['optLeave']);
$leave_type = $opt_leave[0];
$leave = $opt_leave[1];
//now you can use $leave_type to check your conditions by switch or if conditional statements

if($leave_type == 'sleave') {
  // action on sick leave
} else if($leave_type == 'uleave') {
 // action on Union leave
}
new to javascript. I am trying to pass the value of a radio button as the name of an object in a javascript function

new to javascript. I am trying to pass the value of a radio button as the name of an object in a javascript function


By : Никита Орлов
Date : March 29 2020, 07:55 AM
it fixes the issue There are a few problems here.
First, you cannot assign a JavaScript object as the value of an input element. Input element values can be strings only. What we can do with the value is have it contain the key of the ToolBelt object that we want to target:
code :
<input type="radio" name="speak" value="commentary" onClick="ToolBelt.handleClick(this)">commentary a
<br/>
<input type="radio" name="speak" value="commentary1" onClick="ToolBelt.handleClick(this)">commentary b
handleClick: function (el) {
    this.speak(this[el.value]);
}
currentCommentaryKey: null,
handleClick: function (el) {
    this.currentCommentaryKey = el.value;
}
speak: function () {
    if (!this.hasOwnProperty(this.currentCommentaryKey)) { return; }
    var i = this[this.currentCommentaryKey];
    /* rest of speak method implementation */
}
When I pass to another radio button both buton's values come

When I pass to another radio button both buton's values come


By : user3210167
Date : March 29 2020, 07:55 AM
Any of those help I want to do two radio buttons. Their names will be car and home. If I click car, an input box about the car section will be shown and if I click home, an input box about the home will be shown. , HTML
code :
<div>
    <input type="radio" name="option" value="car" onclick="toggleInput(this)" /> Car

    <input type="radio" name="option" value="home" onclick="toggleInput(this)" /> Home
</div>
<div id="car-input-group" class="hide">
    Car InputBox
    <input name="name" type="text" />
</div>
<div id="home-input-group" class="hide">
    Home InputBox
    <input name="name" type="text" />
</div>
function toggleInput(obj){
    var a =document.getElementsByClassName("hide");
    for(var i=0; i<a.length; i++){
      a[i].style.display = "none";
    }
    document.getElementById(obj.value + "-input-group").style.display = "block"
}
.hide{
    display: none
}
Javascript: How can I enable a radio button when 15 other radio buttons are checked with the same class?

Javascript: How can I enable a radio button when 15 other radio buttons are checked with the same class?


By : Mandip Sangha
Date : August 24 2020, 03:00 PM
like below fixes the issue just use the document.getElementsByClassName to get them all, keep track of the values (AKA, check if all of the values are true with a function), add a few eventlisteners for when it is checked, then once its clicked etc, then check them all to see if the value of all is true. For example:
code :
var checkedBoxes = Array.apply(null,document.getElementsByClassName("myClassName"));
checkedBoxes.forEach(x => {
    x.addEventListener("click", onActive);
    x.addEventListener("focus", onActive);
    x.addEventListener("blur", onActive);
    //other event listeeners
});
function checkAll() {
     return !checkedBoxes.find(x => !x.checked) //can't find any radio button whose value is false, which means they are all true, which means they are all checked
}
function onActive(e) {
    if(checkAll()) {
        //activate next button
    }
}
Related Posts Related Posts :
  • Why is my jquery code not working or throwing any errors?
  • Javascript/jquery - Wrap text with tag at specific position
  • Javascript Canvas can't draw multiple curves
  • Javascript move entire span with arrow keys
  • How to stop my character from going outside the div?
  • How to call in plugin options in jquery plugins
  • Remove default submit on modal form button
  • Generate angular model properties by view, when view fields are empty
  • AngularJS - project files layout, injection and scope clarification
  • get text fields that are not empty
  • Jasmine Async Callback Timeout
  • Attach jQuery inputmask to DOM element
  • Error when checking checkbox property
  • JWPlayer 7 error on setup function not working
  • Chaining async Promises with 1 resolve and 1 reject?
  • Create websocket server to send/receive complex objects using SuperWebSocket
  • Pass variable from php to javascript function argument
  • How to update ng-repeat after POST of new items to server
  • How to use firebase-tools as a module and to deal with promises
  • How to get Factorial of number in JavaScript?
  • how to iterate html elements and swap their values
  • backbone router several root, how to load this properly?
  • 2 Validators Only 1 throwing catchable isvalid error
  • Prevent ng-include content from pre-loading until toggled to show
  • D3: Set filter flood-color based on data
  • Jquery autocomplete not a function
  • Highcharts wrong size on window maximize
  • Why these minified comments in JS don't break the code?
  • Angular $q not working as expected - returning undefined
  • Unable to click or submit button using selenium webdriver js
  • Is it possible to make request between two domains?
  • angularjs dynamically change footer
  • Issue attaching javascript events using variation on module pattern
  • Resize a CSS div box dynamically
  • Add one day to User-Input Day using Javascript in a PDF
  • Change contents of div, on <a> click
  • Waiting for function with a setTimeout to complete without tampering with that function
  • JqueryUI (Ajax) Hide() works, Show() does not
  • Nodejs, Express + Angular POST 404
  • Most performance optimal foreach function with getting index
  • How to add live search to Rails 4.2?
  • Why my jQuery function getJSON is not calling my function callback?
  • Passing more parameters into callback function
  • Should.js chaining multiple assertions on a single property
  • Buttons/toggles not working in jquery
  • Smooth scrolling workaround
  • Date math works on Chrome but not on Firefox or Safari
  • Google Analytics in AngularJS. Cannot see real-time page viewing
  • Smooth canvas line and on curser start point
  • RequireJS not loading createjs
  • Highcharts tooltip bug with stacked column chart
  • Javascript - UTC date to local date
  • ngMock complains unexpected request when request is expected
  • Array not sorting correctly in javascript
  • Angular get offset of element by id
  • Validate date with jquery and help user
  • How to start with javascript code obfuscation? Not looking for tools
  • Click doesn't work on this Google Translate button?
  • Vue.js: Using prerendered html as template for parent and child components
  • Bind to model from child directive where model has not been resolved at compile-time
  • shadow
    Privacy Policy - Terms - Contact Us © animezone.co