Nijn
Nijn

Reputation: 400

Get jQuery variable in php without $_GET

I'm using the dialog() function from the jQuery UI. This pops up a dialog where the user will select a value. This value then needs to be returned in the PHP page.

This is my jQuery code

$(function() {
var portal_id = $( "#portal_id" ),
  allFields = $( [] ).add( portal_id );

$( "#dialog-form" ).dialog({
  autoOpen: false,
  height: 300,
  width: 350,
  modal: true,
  buttons: {
    "Selecteer afbeelding": function() {
      var bValid = true;
      allFields.removeClass( "ui-state-error" );

      bValid = "portal_id";

      if ( bValid ) {
        $( "#portal_id" ).append( "<tr>" + "<td>" + portal_id.val() + "</td>" +
        "</tr>");
        $( this ).dialog( "close" );
      }
    },
    Cancel: function() {
      $( this ).dialog( "close" );
    }
  },
  close: function() {
    allFields.val( "" ).removeClass( "ui-state-error" );
  }
});

$( "#select_portal" )
  .button()
  .click(function() {
    $( "#dialog-form" ).dialog( "open" );
  });
});

This returns a value in my php:

<table id="portal_id" class="ui-widget ui-widget-content">
<tr class="ui-widget-header ">
<th>Portal_id</th>
</tr>
<tr><td></td></tr>
<!--- The value is returned here as: <tr><td>portal_id.val()</td></tr> --->
</table>

How can I get the portal_id.val() to return in for example:

 <input type="text" id="name" value="portal_id.val()" />

Upvotes: 0

Views: 87

Answers (1)

Barmar
Barmar

Reputation: 781098

This will copy the value from #portal_id into #name:

$("#name").val(portal_id.val());

Upvotes: 1

Related Questions