Dinesh Vishwakarma
Dinesh Vishwakarma

Reputation: 666

How to pass class value from jquery into input box

index.php

 <span class="final_build_price" data-from="0" data-to="" data-speed="500" data-refresh-interval="10">0</span>
<form method="post" action="">
    <input type="text" id="finalvalue" value="">
    <input type="submit" class="getquote" value="submit" name="send">    
</form>

js

<script>
    $(".dim_price").countTo();
    $(".final_build_price").countTo();
    var finalpice=$(".final_build_price").countTo()
    $('.getquote').click(function(){
        // var fp = JSON.stringfy(finalpice);
        var fp =parseInt(finalpice);
        alert(fp);
        // document.getElementById("final_price").innerHTML=fp;
    });
</script>

<script>
    $(".dim_price").countTo();
    var finalpice=$(".final_build_price").countTo()
    $('.getquote').click(function(){
        // var fp = JSON.stringfy(finalpice);
        var fp =parseInt(finalpice);
        alert(fp);
        document.getElementById("final_price").innerHTML=fp;
    });
</script>

In span class(final_build_price) i am getting a value from below mention jquery but I want to pass that value into input box on click on submit button and the javascript code i used is mentioned below. but I am not getting any data into input box

Upvotes: 0

Views: 168

Answers (1)

P. Frank
P. Frank

Reputation: 5745

This issue is due to write id in place to class and name of your element.

replace

document.getElementById("final_price").innerHTML=fp;

by

$(".final_build_price").html(fp);

Upvotes: 1

Related Questions