Passing PHP Result to JS via jQuery .get -


i have several instances form brought page in overlay via ajax. on these forms have "math validation" question (i know not secure). using following generate problem:

<?php     $randomnum = rand(0,9);     $randomnum2 = rand(0,9);     $randomnumtotal = $randomnum + $randomnum2; ?> 

the random number displayed in text box so:

<input type="text" name="somename" value="<?= $randomnum ?> + <?= $randomnum2 ?>" readonly> 

and validated:

... somename: {     required: true,     equal: <?php echo $randomnumtotal; ?>     }     ... 

this works fine when form on page, hidden , displayed .click function. store files remotely , display them via ajax. no problem doing that, problem when this, numbers generated don't match value. i've tried putting php $randomenumtotal function on both form brought in via ajax , on parent page. neither works.

so question this: can store php function in remote file "random.php", pass value via .get? if so, how make "somename" value equal value file?

<script>   $.get( 'random.php', function ( data ) {     $("somename").val('random.php')?//i know isn't right  }); </script> 

thanks!

$.get( 'random.php', function ( data ) {     $("somename").val(data); }); 

should work. alternatively, use jquery's load() if wanted load content in html of element.


Comments

Popular posts from this blog

linux - Mailx and Gmail nss config dir -

c# - Is it possible to remove an existing registration from Autofac container builder? -

php - Mysql PK and FK char(36) vs int(10) -