maxisme
maxisme

Reputation: 4245

How to translate information written into text form to javascript?

This is my attempt at my question

I have a search box (HTML):

<form method="post">
    Search:<input type="text" name="search">
    <input value="Search" type="submit">
</form>

I then have php:

$search =  $_POST["search"];

And then Jquery:

$(function() {
    var foundin = $('li:contains("    /* I want this part to be the bit entered by the form... $search */   ")').css( "color", "red" );
});

But I can't seem to get the php into jQuery.

Upvotes: 1

Views: 66

Answers (3)

Paddyd
Paddyd

Reputation: 1870

Try changing it to :

$(function() {
    var foundin = $('li:contains(" <?php echo $search ?> ")').css( "color", "red" );
});

Upvotes: 1

WebNovice
WebNovice

Reputation: 2220

$(function(){
    var foundin = $('li:contains("<?php echo $search; ?>").css("color", "red");

Upvotes: 1

Daan
Daan

Reputation: 12236

var my_php_var = <?php echo json_encode($search) ?>

Upvotes: 1

Related Questions