Change href attribute in jquery with php

499 Views Asked by At

$('.buttonFinish').addClass('btn btn-default');

Jquery code for the submit looks like this:

finish  : $('<a>'+options.labelFinish+'</a>').attr("href","#").addClass("buttonFinish")

I need to replace "#" in href with a variable that I can send thru my PHP code.

I tried to do this:

 finish  : $('<a>'+options.labelFinish+'</a>').attr("href","<?php echo $someVariable;?>").addClass("buttonFinish")

where $someVariable is defined in the PHP code where the form submission link will point to

2

There are 2 best solutions below

1
On

You can define a variable in php and call it in JS. For example...

PHP

$someVariable = <?php echo $something ?>

JS

finish  : $('<a>'+options.labelFinish+'</a>').attr("href", $someVariable).addClass("buttonFinish")
1
On
var someVariable = "<?php echo $something ?>";

finish  : $('<a>'+options.labelFinish+'</a>').attr("href", someVariable).addClass("buttonFinish")