javascript data to form hidden file in php

115 views Asked by At

In my mvc application i used raty for rating my image. Here is my code

<div class="container">
<form method="post" class='form' role='form' action="?section=photo&view=addVote">
    <input type="hidden" name="photoId" value="<?php echo $photoinfo['id']; ?>"></input>
    <input type="hidden" name="score" value="<?php  ?>"></input>

    <div class="row">            
        <div>
            <img src="<?php echo base_url(); ?>images/photo_booth/<?php echo $photoinfo['image_name'];?>" class="img-rounded img-define" width="580" height="350"></img>
        </div>
        <div>
            <h6><?php echo $photoinfo['title'] ?></h6>
        </div>
        <div>
            <p class="paragraph"><?php echo $photoinfo['description'] ?></p>
        </div>            
        <div>                
            <div id="raty"></div>
            <button type="submit" class="btn btn-primary button_new submit-btn">Add Vote</button>
        </div>            
    </div>
</form>

<script type="text/javascript">
    $('#raty').raty({
        score: <?php echo $photoinfo['vote']; ?>,                                                    
        number: 10,
        starOn: "<?php echo base_url(); ?>icons/star-on.png",
        starOff: "<?php echo base_url(); ?>icons/star-off.png",
        readOnly: false  
    });

    $("#raty > img").click(function(){
        var score=$(this).attr("alt");     
    });
</script>

Here i can save my score=$(this).attr("alt"); to database using javascript. But i need it to be passed as a hidden field data something like this <input type="hidden" name="score" value="<?php the score of raty! ?>"></input> . Here addVote is a method where i have to do the operation. can i do that? if another way exist so how?Thanks.

2

There are 2 answers

0
Amit Kumar On

Write php inside javascript as string can solve your problem:-

score: "<?php echo $photoinfo['vote']; ?>"
0
Padmanathan J On

you forgot a " " in your php

 score: <?php echo $photoinfo['vote']; ?>, 

you can use score: "<?php echo $photoinfo['vote']; ?>",

instend of score: <?php echo $photoinfo['vote']; ?>,