Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Radio Button information pass with ajax

Tags:

jquery

ajax

php

I have this code which I use to post variables with ajax.

I am passing a radio button, and it takes one value, I mean it doesn't take the selected values, it takes one by default.

Here are my codes: HTML

<input type="radio"  id="status" name="status" value="1" /> Mbyllur<br />
<input type="radio"  id="status" name="status" value="0" /> Hapur<br />

Javascript

 var js_status = $("#status").val();

It takes the first value. What am I doing wrong? Thanks

PHP

$postStatus = filter_var($_POST["postStatus"], FILTER_SANITIZE_STRING);
like image 936
Ozi Oz Avatar asked Dec 04 '25 17:12

Ozi Oz


1 Answers

You've given them both the same ID. When you're searching it by ID, which one is it to reference?

You want something like this:

var js_status = $('input[name=status]:checked').val()
like image 183
Menztrual Avatar answered Dec 08 '25 09:12

Menztrual



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!