0

I'm trying to pass a Jquery variable to a php variable on the same page when the list item changed

<select name="RegistrationTypeID"class="formselectbox"id="RD"
onchange="getText(this.val)">

<option value="">Select Registration Type</option>                                               
<option value="1">Contractor</option>
<option value="2">Exhibitor</option>
<option value="3">Media</option>
<option value="4">Organizer</option>
<option value="5">VIP</option>
<option value="6">Visitor</option>                                           
</select>

function getText(text){

var a = $("#RD option:selected").text();

  // i want variable  a to `php` variable a. on same page  
}
2
  • You can use AJAX to pass the variable to the server. Commented Aug 18, 2019 at 8:49
  • Also take care with the spaces in and around your attributes Commented Aug 18, 2019 at 9:16

1 Answer 1

0

This can be done by creating a http request to your php page like so:

var a = $("#RD option:selected").text();
$.get( "test.php", { variable: a } );

What you do here is send a request to the php file with a parameter named variable with the value of a.

In your php you need to store the data this you can do with sessions

Sign up to request clarification or add additional context in comments.

3 Comments

So we can use $_GET to get this variable as a php variable after using $.get( "test.php", { variable: a } );
my page URL is coded so we think we should use $(location).attr('href'); localhost/event_registration/admin/index.php?0/…
You could use that or the plain js way window.location.href

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.