I have a dynamically generated radio button as fiven below
echo '<tr>
<td colspan="2">Login System</td>
<td colpan="2">
<input type="radio" name="login_system'.$i.'" value="COMMON" checked="checked" />Common  
<input type="radio" name="login_system'.$i.'" value="INDIVIDUAL">Individual
</td>
</tr>';
and i need to take its value using javascript. Below is the code i have written for that
d['login_system']=$('input[name="login_system'+index+'"]').val();
But always I am getting value of first radio button even if I have selected second.
Can anyone help me?
$('input[name="login_system'+index+'"]:checked').val()
Related
Currently I am using this to submit a quantity of 1 product to my cart page with a simple Onclick add to cart button.
<td class="data_cell dataFontColor">
<label onClick="location.href='cart/?PartNo=#NPart#&Qty=1'">Add to
Cart</label></td>
<td class="data_cell dataFontColor">
<cfif IsDefined ("getPrice2.Price") AND getPrice2.Price eq "">
I am trying to implement a text box to submit any quantity the user wants, but on submit the page moves but nothing is added to cart. I know it's something wrong with the Qty= in the OnClick, but can't seem to figure it out. Any help would be appreciated!
<td class="data_cell dataFontColor">
<td><input type="text" name="Qty" size="4" value= "Qty" maxlength="9"/></td>
<td class="data_cell dataFontColor">
<label onClick="location.href='shop/?PartNo=#NPart#&Qty=#Trim (Qty)#'">Add to
Cart</label></td>
The reason this is not working is because you can't do what you're attempting using ColdFusion which processes the page server-side. User typed inputs are processed client-side.
First, I would add an id attribute to your input tag.
<input type="text" id="Qty" name="Qty" size="4" value= "Qty" maxlength="9"/>
Once your input has an ID, now you can now extract the value client-side using JavaScript.
<label onClick="location.href='shop/?PartNo=#NPart#&Qty="+document.getElementById("Qty").value.trim()>Add to Cart</label>
I need some help with my code as I have got a problem with posting the value. When I click on the radio, it will not post the data when it redirect me to secondpage.php. I want to post the value when I click on the radio button to take me to the next page.
firstpage.php
<table>
<form name="frmProfile" method="post" action="secondpage.php">
<tr>
<td>gender</td>
<td><input type="radio" name="gender" onclick="document.location.href='http://example.com/secondpage.php'" data-gender="female" value="female">Female
<input type="radio" name="gender" onclick="document.location.href='http://example.com/secondpage.php'" data-gender="male" value="male">Male</td>
</tr>
<tr><td colspan="2"><input type="submit" name="submit" value="Submit" /></td></tr>
</form>
</table>
secondpage.php
print_r($_POST);
?>
It will show the empty data in the $_POST as I will get the results which it show Array ( ) when I am using print_r($_POST) in secondpage.php.
What I am trying to achieve is when I click on a radio button, I want to post the data to redirect me to secondpage.php and display the data of Male or Female depends on the radio button that I click on.
Can you please show me an example how I could post the value of the radio that I select on to redirect me to the secondpage.php to display the data of $_POST?
Thank you.
You can bind a click event listener to the form. When a click happens, check if it originated from one of the radio elements. If it did, submit the form.
document.getElementById('genderForm').addEventListener('click', function(e){
// 'this' is the genderForm
if (e.target.name === 'gender') this.submit();
});
<form id="genderForm" name="frmProfile" method="post" action="secondpage.php">
<table>
<tr>
<td>gender</td>
<td>
<input type="radio" name="gender" value="female">Female
<input type="radio" name="gender" value="male">Male
</td>
</tr>
</table>
</form>
I have two radio buttons and the session to store which button is selected, which I want to access in my second page.
On selection of each radio button, there will be different fields to be displayed in second page which is modal.
For example, if user selects first one (e.g.: date and time filled should be hidden) on second it should display. How to do this?
<td>
<label class="radio-inline"><input type="radio" name="reason" value="1">Executed</label>
</td>
<td>
<label class="radio-inline"><input type="radio" name="reason" value="2">Expired</label>
</td>
<td>
<label class="radio-inline"><input type="radio" name="reason" value="3">Another Option</label>
</td>
and PHP code
//$reason = $_REQUEST['reason']; OR
$reason=$_POST['reason'];
this is your form data and you can change action if you want . suppose first submit form in same page2 then use this code
<form method="post" action="page2.php">
<input type="radio" name="reason" value="1"/>Reason1
<input type="radio" name="reason" value="2"/>Reason2
<input type="radio" name="reason" value="3"/>Reason3
<input type="submit" value="submit"/>
</form>
in second page this is code
and you want to use this value any place then use this code in your any place from project
<?php
session_start();
$reason = $_SESSION['reason'];
echo $reason;
?>
Assume that, there are many checkboxes in any site and they are unchecked. Site works in any server. I have not site code. I want to make checked some of those checkboxes. To find checkboxes by value of <td> Can I do this with JavaScript? How can I run JavaScript code in that site code? My aim is to show checkboxes as "checked".
<tr>
<td id ="id1" name"name1">value1</td>
<td><input id="checkid1" name="checkname1" type="checkbox" value="false"></td>
</tr>
<tr>
<td id ="id2" name"name2">value2</td>
<td><input id="checkid2" name="checkname2" type="checkbox" value="false"></td>
</tr>
<tr>
<td id ="id3" name"name3">value3</td>
<td><input id="checkid3" name="checkname3" type="checkbox" value="false"></td>
</tr>
If it is possible, I want to enter, value1, value2 and JavaScript will make checked related checkboxes.
You can achieve this with JQuery.
Check if a checkbox is checked and than set checked true for the desired other checkboxes.
http://jquery-howto.blogspot.be/2008/12/how-to-check-if-checkbox-is-checked.html
To search by value you can do something like this:
$("input:checkbox[value=val]").attr("checked", true);
I am working with a SharePoint site and I cannot change the HTML. What I am trying to do is to get which radio button is selected but they are wrapped in span's. If I go by title on the span and then .next() I get the next element after the span which is incorrect so how should I do this?
HTML:
<span dir="none"><table cellpadding="0" cellspacing="1">
<tr>
<td><span class="ms-RadioText" title="Tasmania"><input id="ctl00_m_g_f1c8ac33_8a36_42be_8901_5201d5b9eede_ctl00_ctl04_ctl02_ctl00_ctl00_ctl04_ctl00_ctl00" type="radio" name="ctl00$m$g_f1c8ac33_8a36_42be_8901_5201d5b9eede$ctl00$ctl04$ctl02$ctl00$ctl00$ctl04$ctl00$RadioButtons" value="ctl00" /><label for="ctl00_m_g_f1c8ac33_8a36_42be_8901_5201d5b9eede_ctl00_ctl04_ctl02_ctl00_ctl00_ctl04_ctl00_ctl00">Tasmania</label></span></td>
</tr><tr>
<td><span class="ms-RadioText" title="Greenland"><input id="ctl00_m_g_f1c8ac33_8a36_42be_8901_5201d5b9eede_ctl00_ctl04_ctl02_ctl00_ctl00_ctl04_ctl00_ctl01" type="radio" name="ctl00$m$g_f1c8ac33_8a36_42be_8901_5201d5b9eede$ctl00$ctl04$ctl02$ctl00$ctl00$ctl04$ctl00$RadioButtons" value="ctl01" /><label for="ctl00_m_g_f1c8ac33_8a36_42be_8901_5201d5b9eede_ctl00_ctl04_ctl02_ctl00_ctl00_ctl04_ctl00_ctl01">Greenland</label></span></td>
</tr><tr>
<td><span class="ms-RadioText" title="Hawaii"><input id="ctl00_m_g_f1c8ac33_8a36_42be_8901_5201d5b9eede_ctl00_ctl04_ctl02_ctl00_ctl00_ctl04_ctl00_ctl02" type="radio" name="ctl00$m$g_f1c8ac33_8a36_42be_8901_5201d5b9eede$ctl00$ctl04$ctl02$ctl00$ctl00$ctl04$ctl00$RadioButtons" value="ctl02" /><label for="ctl00_m_g_f1c8ac33_8a36_42be_8901_5201d5b9eede_ctl00_ctl04_ctl02_ctl00_ctl00_ctl04_ctl00_ctl02">Hawaii</label></span></td>
</tr>
</table></span>
I am trying to not use the name of the radio button group as this can change.
Thanks in advance.
$('span > input:radio:checked')
This will select all input elements, which are checked, and are direct child of span elements.
Demo
If you want the selected radio buttons:
$(".ms-RadioText input:radio:checked")
$(".ms-RadioText > input[type='radio']:checked").val();
Like this for example:
$("span.ms-RadioText input[type=radio]:checked") // returns list of all inputs that are children of spans.
$("span.ms-RadioText input[type='radio']:checked").value('this one is selected');